title: Update collection of a related entity with the newly created/deleted object (onFlush)
body: <p>I have the following setup of Doctrine entities:</p>
  
  <pre><code>class MainEntity
  {
      /**
       * @var SecondEntity[]
       *
       * @ORM\OneToMany(targetEntity="SecondEntity", mappedBy="mainEntity", cascade={"persist"})
       */
      private $secondEntities;
  
      /**
       * @var integer
       *
       * @ORM\Column(type="integer", nullable=false, name="second_entities_count")
       */
      private $secondEntitiesCount;
  
      ...
  }
  
  class SecondEntity
  {
      /**
       * @var MainEntity
       *
       * @ORM\ManyToOne(targetEntity="MainEntity", inversedBy="secondEntities")
       * @ORM\JoinColumn(name="main_entity_id", referencedColumnName="id", nullable=false)
       */
      private $mainEntity;
  
      ...
  }
  </code></pre>
  
  <p>When a <code>SecondEntity</code> is created or deleted, I want the <code>$secondEntitiesCount</code> in the related <code>MainEntity</code> to be updated accordingly.</p>
  
  <p>To achieve this, I have created an <code>onFlush</code> subscriber that gathers all scheduled deletions and insertions of <code>SecondEntity</code> objects</p>
  
  <pre><code>$delsertions = array_merge(
      $unitOfWork-&gt;getScheduledEntityInsertions(),
      $unitOfWork-&gt;getScheduledEntityDeletions()
  );
  foreach ($delsertions as $entity) {
      if ($entity instanceof SecondEntity) {
          $mainEntity = $entity-&gt;getMainEntity();
  
          $mainEntityMeta = $em-&gt;getClassMetadata(MainEntity::class);
          $unitOfWork-&gt;recomputeSingleEntityChangeSet($mainEntityMeta, $mainEntity);
  
          dump($mainEntity-&gt;getSecondEntities); // The creation/deletion of the current entity is not reflected here!
      }
  }
  </code></pre>
  
  <p>The problem is that in the <code>dump()</code> above, the collection has not been updated accordingly after the creation/deletion of the entity that triggered the subscriber. For example, if I'm creating the first <code>SecondEntity</code> for a given <code>MainEntity</code>, the <code>$secondEntities</code> collection will be empty.
  And if I'm deleting the only <code>SecondEntity</code>, the <code>$secondEntities</code> collection would still have that object inside it.
  The <code>recomputeSingleEntityChangeSet()</code> call doesn't seem to do anything in this case.</p>
  
  <p>How can I force the collection to be properly updated?</p>