symfony - Event Subscriber postUpdate query is not updated -


i'm trying compare data on database before , after upgrade, in order perform operations.

specifically:

association: artist manytomany soundtrack.

when remove artist record soundtrack, check if artist has been without associations, if true removes artist.

public function postupdate(lifecycleeventargs $args) {     $entity = $args->getentity();     $em = $args->getentitymanager();      if ($entity instanceof soundtrack) {         //$this->difference contains difference between artists before , artists after change.         if(!empty($this->difference)) {             foreach($this->difference $m) {                 $art = $em->getrepository('acmeuserbundle:artist')->findartistbyidjoinsoundtrack($m);                 var_dump($art->getid());              }         }     } } 

query findartistbyidjoinsoundtrack():

public function findartistbyidjoinsoundtrack($id) {     $qb = $this->createquerybuilder('a');          $query = $qb->select(array('partial a.{id}'))                  ->innerjoin('a.soundtrack', 's')                  ->where('a.id = :id')                  ->setparameter('id', $id)                  ->setmaxresults(1)                  ->getquery();           return $query->getsingleresult(); } 

the problem comes when run query see if artist has been without associations, in fact querying in postupdate:

$em->getrepository('acmeuserbundle:artist')->findartistbyidjoinsoundtrack($m); 

for example, if artist had 1 association soundtrack id 71 , removed soundtrack id 71 artist, query not return empty response returns element soundtrack 71 id.

in other words if database not updated despite having used event postupdate invoked after flush().

why happen?

i cleared cache several times make sure not that's problem!

please have @ my answer here. changing related entities not allowed using preupdate listener. thought ...

[...] event postupdate [...] invoked after flush().

... not correct - postupdate not invoked after flush() inside.

the 3 post [postupdate, postremove, postpersist] events called inside entitymanager#flush(). changes in here not relevant persistence in database.

(documentation)


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -