I'm trying to detect changes in a many-to-many relation in an onFlush
event.
If new entities are added to the relation or the relation is updated (always keeping an element), I can detect changes using $unitOfWork->getScheduledCollectionUpdates()
and then check for getInsertDiff()
or getDeleteDiff()
. So far so good.
The problem comes when I take all the entities out of the relation: "There were two related entities before but there are NO related entities now."
When the relation is left empty I can access $unitOfWork->getScheduledCollectionDeletions()
, but there is no way of knowing which entities were deleted:
getDeleteDiff()
for this collections doesn't tell anything.getSnapshot()
doesn't tell me which entities were there before
How should I know which entities were taken out of the many-to-many relation?
I've added a Gist with the full implementation: everything works ok (it may need some optimization) except $uow->getScheduledCollectionDeletions()
(line 101)
$uow->getScheduledCollectionUpdates()
and$uow->getScheduledCollectionDeletions()
both return arrays of collections. And those collections behave independently of where they are used. What exactly are you trying to accomplish? It seems like you want to "do something" with entities that are inserted or deletion into/from the db. If this is true, then you only need$uow->getScheduledEntityInsertions()
(which will contain all entities that will be inserted) and$uow->getScheduledEntityDeletions()
(which will contain all entities that will be deleted).$uow->getScheduledCollectionDeletions()
, but I can't find any reference to the deleted Labels there. I'm sure the solution is pretty easy, but I can't find any documentation online...