If you need to avoid duplicates on that particular constraint, then you need to run a separate query/check to verify if those values already exist. Doctrine won't do that automatically for you.
Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ On 2 April 2014 13:33, Ayham Alzoubi <[email protected]> wrote: > Hey everyone > > I am trying to add constraints to doctrine entity to catch the exception > when we add duplicates fields to the database > > Currently i am getting sql error but i need doctrine to catch the error > before executing the query > > in my code i have Composite id from two IDs, one of them is FK to other > entity > > here is my code: > > /** > * > * @ORM\Table(name="myEntity") > * @UniqueEntity( > * fields={"id1", "id2"}, > * message="id1, id2 are in use" > * ) > * > * @ORM\Entity > * @ORM\HasLifecycleCallbacks() > */ > class myEntity > { > /** > * @var id1 > * > * @ORM\Id > * @ORM\ManyToOne(targetEntity="otherEntity") > * @ORM\JoinColumns({ > * @ORM\JoinColumn(name="id1", referencedColumnName="id_otherEntity") > * }) > */ > private $id1; > > /** > * @var int > * > * @ORM\Id > * @ORM\Column(name="id2", type="integer", nullable=false) > */ > private $id2; > } > > Thanks > > -- > You received this message because you are subscribed to the Google Groups > "doctrine-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/doctrine-user. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
