php - Update total relation counter in Doctrine -


stupid question, can't find answer.

i need execute query this:

$em     ->createquerybuilder()     ->update('appbundle:contest\member', 'm')     ->innerjoin('m.votes', 'v')     ->set('m.total_votes', 'count(v.id)')     ->where('m.id = :member')     ->setparameter('member', $member->id())     ->getquery()     ->execute() ; 

or through dql

update     appbundle:contest\member m inner join     m.votes v set     m.total_votes = count(v.id)     m.id = :member 

doctrine categorically refuse execut query.

what doing wrong?

i found solution

$total = $em     ->getrepository('appbundle:contest\member\vote')     ->createquerybuilder('v')     ->select('count(v.id)')     ->where('v.member = :member')     ->setparameter('member', $member->getid())     ->getdql() ;  $em->createquerybuilder()     ->update('appbundle:contest\member', 'm')     ->set('m.total_votes', '('.$total.')')     ->where('m.id = :member')     ->setparameter('member', $member->getid())     ->getquery()     ->execute() ; 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -