Answer the question
In order to leave comments, you need to log in
Can't use unique-constraints on boolean or how to create partial index?
<entity name="App\Domain\UserPack\Email\Entity\UserEmail"
...
<unique-constraints>
<unique-constraint columns="user_uuid,isActive" name="unique_user_active_email"/>
<unique-constraint columns="user_uuid,isFallback" name="unique_user_fallback_email"/>
</unique-constraints>
...
<embedded name="isFallback" class="App\Domain\UserPack\Email\ValueObject\UserEmailIsFallback"
use-column-prefix="false"/>
<embedded name="isActive" class="App\Domain\UserPack\Email\ValueObject\UserEmailIsActive"
use-column-prefix="false"/>
...
<many-to-one target-entity="App\Domain\UserPack\User\Entity\User"
field="user"
inversed-by="emails"
>
<cascade>
<cascade-persist/>
</cascade>
<join-column name="user_uuid" referenced-column-name="uuid"/>
</many-to-one>
<unique-constraint columns="user_uuid,email" name="unique_user_active_email"/>
Answer the question
In order to leave comments, you need to log in
I don't have any problems creating unique-constraints for boolean.
https://www.postgresql.org/docs/current/indexes-pa...
* @ORM\Table(name="table",
* uniqueConstraints={
* @ORM\UniqueConstraint(name="only_one_true_primaryuix", columns={"id_table", "is_primary"}, options={"where":"is_primary"})
* },
* indexes={
* ///index
* })
uniqueConstraints
, then doctrine has problems with composite keys PRIMARY KEY ("id_1", "id_2"),
and they work only in a very primitive form and it is strongly recommended to replace them with one primary key and use them uniqueConstraints
to emulate a composite key.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question