Note that there are some explanatory texts on larger screens.

plurals
  1. POEvent Subscriber postUpdate query is not updated
    text
    copied!<p>I'm trying to compare data on the database before and after an upgrade, in order to perform the operations.</p> <p>Specifically:</p> <p>Association: Artist ManyToMany Soundtrack.</p> <p>When I remove an artist by a record soundtrack, I check if that artist has been without associations, if true removes the artist.</p> <pre><code>public function postUpdate(LifecycleEventArgs $args) { $entity = $args-&gt;getEntity(); $em = $args-&gt;getEntityManager(); if ($entity instanceof Soundtrack) { //$this-&gt;difference contains the difference between the artists before and the artists after the change. if(!empty($this-&gt;difference)) { foreach($this-&gt;difference as $m) { $art = $em-&gt;getRepository('AcmeUserBundle:Artist')-&gt;findArtistByIdJoinSoundtrack($m); var_dump($art-&gt;getId()); } } } } </code></pre> <p><strong>query findArtistByIdJoinSoundtrack():</strong></p> <pre><code>public function findArtistByIdJoinSoundtrack($id) { $qb = $this-&gt;createQueryBuilder('a'); $query = $qb-&gt;select(array('partial a.{id}')) -&gt;innerJoin('a.soundtrack', 's') -&gt;where('a.id = :id') -&gt;setParameter('id', $id) -&gt;setMaxResults(1) -&gt;getQuery(); return $query-&gt;getSingleResult(); } </code></pre> <p>The problem comes when I run a query to see if the artist has been without associations, in fact querying in postUpdate:</p> <pre><code>$em-&gt;getRepository('AcmeUserBundle:Artist')-&gt;findArtistByIdJoinSoundtrack($m); </code></pre> <p>for example, if an artist had only one association with the soundtrack with id 71 and I just removed from the soundtrack with id 71 that artist, the query does not return an empty response but returns an element soundtrack with just 71 id.</p> <p>In other words it is as if the database is not updated despite having used the event postUpdate that is invoked after the flush().</p> <p>Why does this happen?</p> <p>I also cleared the cache several times to make sure it was not that's the problem!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload