php - Doctrine's "options" property in @UniqueConstraint not working -


context

i'm using doctrine version 2.5.0 , have 2 entities: group , item. i'm trying create unique constraint items cannot have same position in group:

/** * @entity * @table(uniqueconstraints={ *            @uniqueconstraint(name="position", columns={"group_id", "position"}) *       ) */ class item {     ... } 

this works well.


problem

i added active field item entity, instead of deleting item, 'inactivate' it. unique constraint doesn't work anymore, since item stays in database group reference , position.


attempts

looking @ doctrine docs, i've discovered can use options property clause in @uniqueconstraint:

/** * @entity * @table(uniqueconstraints={ *            @uniqueconstraint(name="position", columns={"group_id", "position"}, *                              options={"where":"(active = 1)"})} *       ) */ class item {     ... } 

but same error before:

sqlstate[23000]: integrity constraint violation: 1062 duplicate entry '1-1' key 'position'

here deletion code:

$item->setactive(false); $this->_em->persist($item); $this->_em->flush();  foreach ($item->getnextitems() $nextitem) {     $nextitem->setposition($nextitem->getposition() - 1);     $this->_em->persist($nextitem); }  $this->_em->flush(); 

any idea why options property not working?


update

i realised strange behaviour. every time run command ./doctrine orm:schema-tool:update --force recreates index:

drop index position on item; create unique index position on item (group_id, position); 

but once remove options property , run command, get:

nothing update - database in sync current entity metadata.

if have data in database , after adding unique constraint first please check in database have unique values or not.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -