Wednesday 15 August 2012

doctrine2 - MySQL: ignore constraint within SQL transaction -



doctrine2 - MySQL: ignore constraint within SQL transaction -

for collection multiple items want update ordering of items. in mysql have constraint (order + collection_id) unique. so, cannot have 2 items @ order 1 in same collection.

however, want update ordering of items "atomically". orm, updated entities new order , performed flush write them downwards database. orm converts them multiple queries , straight results in constraint violation mysql.

example:

i have items in order a, b, c. a=1, b=2 , c=3. perform update order c, b, a. c=1, b=2, a=1. these 2 queries , first update straight runs constraint violation. in pseudo:

update item set order=1 id=c

my idea

is possible start transaction, remove constraint, apply changes , enable constraint again? if enabling fails, rollback ensure set back.

alternative

an alternative remove constraint altogether, not fond of solution :)

mysql doctrine2 constraints

No comments:

Post a Comment