开发者

Create new user with email as a soft deleted user

开发者 https://www.devze.com 2023-03-21 05:25 出处:网络
I am using ActsAsParanoid for soft deleting users.After deleting(soft) a user, my client wants to create user with same email id.But it generating unique field error since email column i开发者_C百科s

I am using ActsAsParanoid for soft deleting users.After deleting(soft) a user, my client wants to create user with same email id.But it generating unique field error since email column i开发者_C百科s unique.So my question is can we set the uniqueness for email column only if the deleted_at column is null.

Pls reply if u dont understand my question.


I suppose you could change the uniqueness constraint of your users table to be:

UNIQUE (email, deletion_date)

This would effectively:

  • For standard (non-deleted) users, guarantee they have unique email addresses, since their deletion dates would presumably all be NULL.
  • For deleted users, not make any guarantee about email addresses, since they all have unique deletion dates.
  • For new users, allow them to use an email address that a deleted user has, since the new user will have a NULL deletion date, while the deleted user has a value there.


Ah, just change old email to something like

Me@yourmail.com_deleted

That way if you need to view the old email it's everything before the underscore deleted.

In other words here have new user create new account.

Probably have a mutator in the background add the underscore deleted on the old account.

Underscore deleted just an example.

0

精彩评论

暂无评论...
验证码 换一张
取 消