doctrine / orm

Doctrine Object Relational Mapper (ORM)
https://www.doctrine-project.org/projects/orm.html
MIT License
9.91k stars 2.5k forks source link

UnitOfWork Collection Updates #5920

Open peterrehm opened 8 years ago

peterrehm commented 8 years ago

I am not sure wether this is intended and I am misunderstanding a concept or wether this might be a bug.

I am havin a One-To-Many relationship between Quotes and QuoteItems and I would like to do some adjustments in a onFlush listener. However if I add an item to an existing quote I di get the item in $uow->getScheduledEntityInsertions() but I would have expected to see the changes in $uow->getScheduledCollectionUpdates().

Is this expected?

coudenysj commented 8 years ago

http://doctrine-orm.readthedocs.io/projects/doctrine-orm/en/latest/reference/events.html#onflush

OnFlush: It is called inside EntityManager#flush() after the changes to all the managed entities and their associations have been computed.

If you want to change the entity list, you need to let the UoW know (via computeChangeSet, see the link above).

peterrehm commented 8 years ago

@coudenysj I dont want to do additional changes, the question is why I get the changes of a collection through getScheduledEntityInsertions instead of getScheduledCollectionUpdates, same with removals.

andrea-fineschi commented 7 years ago

I see some months has passed, But I'd like to 'reopen' the problem. I've seen that during the flush (in the "commit" method of the class "UnitOfWork"), if I update some entity and some collections as well (update or remove) I found all the updates in "$this->entityUpdates", while "$this->collectionUpdates" is empty. I checked the documentations and I've configured the associations correctly. Someone has any idea?

Ocramius commented 7 years ago

I've seen that during the flush (in the "commit" method of the class "UnitOfWork"), if I update some entity and some collections as well (update or remove) I found all the updates in "$this->entityUpdates", while "$this->collectionUpdates" is empty.

Executing any changes to the entities during flush() execution means that you have to take ownership of these changes, and register them with the UnitOfWork yourself.

andrea-fineschi commented 7 years ago

I'm not sure I explained myself correctly. I don't execute changes during flush; what I meant was that, if I execute some changes to entity and collections, and then I flush, all the changes are in 'entityUpdates' and none in 'collectionUpdates

desmax commented 7 years ago

same problem, any news?

Ocramius commented 7 years ago

all the changes are in entityUpdates and none in collectionUpdates

That's clear now, but it needs a test case.

mrtnzagustin commented 2 years ago

Same problem, since 2017? Uff. Related to https://github.com/doctrine/orm/issues/7365

greg0ire commented 2 years ago

Same problem, since 2017? Uff.

Here's your time to shine! Submit a PR to fix it! Chop chop, the issue isn't going to fix itself!