I have a method which serves to update an entity.
The logic in the method eventually ends up with $em->flush($entity)
.
I also need get all the changes that have been done to that entity outside the method.
I've found a good answer on an almost the same question - Is there a built-in way to get all of the changed/updated fields in a Doctrine 2 entity.
But the problem is that the $uow->computeChangeSets()
in the answer computes all the changes in all the managed entities and if you then call $em->flush($entity)
- it actually will flush all that calculated changes, not just ones of the $entity.
How one can get all the changes in an entity without any side-effects?
Asked
Active
Viewed 48 times
0
-
@LBA I've pointed out in my question that this question doesn't solve my problem completly - and I have explained why. – Vasily Sep 09 '15 at 10:05
-
please have a look in the accepted answer there: You can use also similar methods like Doctrine\ORM\UnitOfWork#recomputeSingleEntityChangeSet(Doctrine\ORM\ClassMetadata $meta, $entity) if you know exactly what you want to check without iterating over the entire object graph. – LBA Sep 09 '15 at 10:19
-
Thanks, I've already had a look at the method, but it seems supposed for internal usage only - it have an `@ingnore` directive and 'INTERNAL:' line. – Vasily Sep 09 '15 at 10:27
-
@LBA But it turns out that the guy who answered the question is from Doctrine developer team, and he said that "You are not supposed to use this API outside lifecycle event listeners of the UnitOfWork", so it seems it is the only way of doing it. So my question is really a duplicate =). Thank you for helping me to figure it out =) – Vasily Sep 09 '15 at 10:31
-
just wanted to answer in the same fashion, I agree it's ugly but it's the only known way and there's a reason why this method is public. you might encounter further issues (e.g. if you try to persist anything new while you're already updating 'preUpdate') - good luck! – LBA Sep 09 '15 at 10:36
-
@LBA Thank you a lot, good luck to you too =). – Vasily Sep 09 '15 at 11:23