0

I'm planning to do this for my application:

  1. Store a unique id into key_name of a User model.
  2. At any time given, user will be allowed to choose a username once, which I intend to replace the original key_name of a model with this username chosen by user.
  3. With my implementation, any new user, the User model will be only created when user is activated.

Based on the situation, my question, which of the following a better approach ?

  1. Upon user log in, user must choose a username, so that I could create the User model with the keyname = username chosen. However, this approach might appears unpleasant to user as they should be allowed to choose username anytime that they wanted to.
  2. The approach explained in situation above, however I would need to do clone_entity. However, with clone_entity, will reference properties be assigned back to the new cloned entity ? And also, performance is priority, will this be costly in terms of database operations if it involves a lot of users at the same time ?
Community
  • 1
  • 1
MrCooL
  • 926
  • 3
  • 15
  • 30

1 Answers1

0

If you're heart-set on having the user_name as the key either approach should work fine (assuming you have the logic to prevent duplicate usernames)

However, with clone_entity, will reference properties be assigned back to the new cloned entity ?

If the clone entity is done correctly reference properties will be copied over without a problem. However if you have any entities referencing the entity you are cloning those will not be updated to reference the new clone of the entity.

And also, performance is priority, will this be costly in terms of database operations if it involves a lot of users at the same time ?

As long as the clone is implemented efficiently and assuming you pass in the entity you want to clone there should only be one database operation per clone call (the put of the newly created entity).

It looks like the the clone_entity you linked has an update that will avoid excess db calls for reference properties so you should be good.

Bovard
  • 1,175
  • 1
  • 14
  • 22