Search code examples
phpsqlsymfonydoctrine-ormdql

Doctrine 2: How to update field with number of children?


If I have two entities: Parent and Child, how can I run a single query and update Parent.number_of_children with the number of the related children?

I could iterate over every parent, but it can be easily done with a single query in MySQL for example, the question is how to do it in Doctrine 2 (with DQL perhaps)?


Solution

  • Until anyone offers a better solution, I will go with the native SQL:

    $entityManager -> getConnection() -> query("...");