dimanche 26 mai 2019

Workaround null unique on soft delete deleted_at column on Laravel

It's known that on multiple column unique indexes, if one of the values is NULL, the entire constraint is broken. Some think this should not be the behaviour, but others think it's the right way to handle such cases.

One proposed workaround it to use, for example, a empty string versus non-empty strings to handle such cases.

I am using Laravel 5 with SoftDeletes on my models. In this pattern, I have a deleted_at column that, when NULL, means it's not deleted; when not-null, represents the time that the row has been deleted. I can't, however, use a default value like the proposed workaround, because it will be treated as deleted by the system.

How may I workaround this on Laravel or MySQL so that I may have deleted_at as a nullable unique index?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2X8Pt83
via IFTTT

Aucun commentaire:

Enregistrer un commentaire