This is intended behavior: When using the change tracking policy "deferred implicit" or "deferred explicit", Doctrine will _calculate_ change-sets for you. When using "notify" it will not, because you notify it of all changes.
Thus if you tell Doctrine to update a field, it will update that field. IMHO it is your responsibility to _not_ change a field of an entity you're going to remove anyway. It doesn't really make sense to do that. -- Jasper N. Brouwer (@jaspernbrouwer) On 6 January 2015 at 23:33:23, [email protected] ([email protected]) wrote: > I use "notify" as the change tracking policy. If a property of an entity is > changed after it has already been removed from the unit of work, then on > the next flush the entity gets an update first before being deleted finally. > > For example, the following code > $em = $this->getDoctrine()->getManager(); > $entity = $this->getDoctrine()->getRepository('MyBundle:Entity')->find( 42 > ); > $em->remove( $entity ); > $entity->setFoo( 4711 ); > $em->flush(); > > results into these database commands > START TRANSACTION; > UPDATE entity SET foo = 4711 WHERE id = 42; > DELETE FROM entity WHERE id = 42; > COMMIT; > > Is this intended behaviour? In the harmless case the update command is just > needless. But in some cases this results into a failing database > transaction, if the updated value of the property is illegal although > everything would be just fine eventually because the entity is deleted > anyway. (The reason is that PostgreSQL cannot defer NOT NULL and CHECK > constraints to the end of a transaction.) Hence, the unpleasant result > looks like > START TRANSACTION; > UPDATE entity SET foo = 4711 WHERE id = 42; > >> ERROR: Failed CHECK CONSTRAINT on column foo .... > > I would never have noted this needless update if I had not got the above > error. > > In my humble opinion Doctrine should recognize that the entity is going to > be deleted anyway and skip all prior update commands. Please note, that > this only seems to happen with change tracking policy "notify", with the > default policy "deferred implicit" everything ist just fine. -- 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.
