[DDC-1775] Notify strategy listener is not attached for new entities Created: 11/Apr/12 Updated: 07/Jul/12 Resolved: 07/Jul/12
|Project:||Doctrine 2 - ORM|
|Reporter:||Oleg Namaka||Assignee:||Benjamin Eberlei|
New entities with Notify strategy for changes and with GeneratedValue(strategy="AUTO") never get the onPropertyChanged listener attached to them. That happens because of the logic in the UOW::scheduleForInsert($entity) method. The last condition in it "isset($this->entityIdentifiers[$oid])" is never true because the identifier is not set and therefore the code that attaches the PropertyChangedListener in addToIdentityMap is never run.
|Comment by Guilherme Blanco [ 23/May/12 ]|
This is intentional to me.
I experimented changing the code to also notify about changed during new and the consequences were very drastic. Internally, propertyChanged creates entityChangesets that implies an UPDATE.
Marking ticket as won't fix.
|Comment by Oleg Namaka [ 24/May/12 ]|
In that case the Notify strategy is partially broken:
OnFlush event handler:
Code that uses the entity:
If there is no explicit call to the addPropertyChangedListener method, the caption field gets saved but the $addedAt remains null after flush. The entity does not have the attached listener so UnitOfWork does not know anything about the update that happened in the OnFlush event, and the recomputeSingleEntityChangeSet method skips entities with Notify strategy.
|Comment by Benjamin Eberlei [ 27/May/12 ]|
Changing computeScheduleInsertsChangeSets() would solve this, but it would also mean that the notifier gets injected more than once.
I think injecting in scheduleForInsert() is ok, but we have to look at potential problems also
|Comment by Benjamin Eberlei [ 07/Jul/12 ]|