Unique field for a Custom Entity
-
I need to create an entity which must have an unique name in it's data.
exp:{ name: "blabla", ... }I can handle it by reading the whole table and check if there is no object with that name and then create the entity, but what can I do with concurrency?
if someone else calls the create api in the same time and the same name it's not in db yet, then I can't notice it's a duplicate name, then we encounter a duplication.
any workaround for this situations? -
Hi Reza, a simple workaround I would recommend is using our atomic methods, such as IncrementGlobalStats, to form the field values with the returned value of that method and some other characters you selected. (defined a global statistic ahead of time, call IncrementGlobalStats() get the returned current value of the global statistic, e.g.
123, then combine with the name you selected to a unique name, such asname_123) -
K kuabs referenced this topic on
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login