@Gedmo\SoftDeleteable and unique fields with NULL value

In this post il will show how to configure Doctrine UniqueConstraint when you have SoftDeleteable extension.

* @ORM\Table(
*     name="persons",
*     uniqueConstraints={
*         @ORM\UniqueConstraint(name="user_unique_username",
*                              columns={"username","account_id"},
*                              options={"where":"(deleted_at IS NULL)"}
*              ),
*     },
* )
* @Gedmo\SoftDeleteable()

This unique index will look like this in SQL :

CREATE UNIQUE INDEX user_unique_username ON public.persons USING btree (username, account_id) WHERE (deleted_at IS NULL);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre user="" computer="" escaped="">