Consider the following scheme:
[Work] id tags ManyToMany(targetEntity="Tag", inversedBy="works", cascade={"persist"}) [Tag] id works_count works ManyToMany(targetEntity="Work", mappedBy="tags")
works_count is the cache counter for Tag::works .
I have an onFlush Job listener that checks if Work::tags has changed and updates each of the works_count tags.
public function onFlush(OnFlushEventArgs $args) { foreach ($uow->getScheduledEntityUpdates() as $work) { $changedTags = $metadata = $em->getClassMetadata('Acme\Entity\Tag'); foreach ($changedTags as $tag) { $uow->recomputeSingleEntityChangeSet($metadata, $tag); } } }
Now, if I read the changes to the updated tag sets, the works_count changes works_count displayed correctly , but they are not updated in the database ..
If I replaced recomputeSingleEntityChangeSet() with computeChangeSet() , then everything will work as expected and the database will update , but computeChangeSet () has @internal Don't call from the outside. annotation on it, so I'm not sure what the consequences are ..
Every Internet source says use recomputeSingleEntityChangeSet , so why doesn't it work in this case?
PS Tags are managed by EntityManager ( $em->contains($tag) returns true)
tamir source share