0

Is it possible to make a Doctrine 2 entity mark itself for removal under certain conditions (e.g. in preUpdate and prePersist lifecycle callbacks if it is a many-to-many transitional entity that has it's both foreign keys nulled)?

G. Kashtanov
  • 401
  • 3
  • 11
  • Don't try to delete the entity from it's prePersist or preUpdate events! Doctirine doesn't allow that, throwing an error that the entity's state is not MANAGED; and that is a documented behaviour (not a bug). However, I found a way to accomplish my task differently: the transitional entity association can be marked as 'orphanRemoval=true' from both referencing sides. A side-effect of it would be that removal of association from just one side will implicitly remove it from another. But this fits my task perfecty. – G. Kashtanov Apr 10 '14 at 17:01
  • take a look on that [answer](http://stackoverflow.com/a/6334710/2043207) – zavalit Apr 10 '14 at 18:43

0 Answers0