Can Doctrine2 load calculated values?
Is there a way to load calculated values i开发者_StackOverflownto an entity using Doctrine2? For example, if a question
has votes
(the votes
table having a foreign key from the question
table), using SQL you could select the question
and calculate a vote total.
Is something like that possible with Doctrine2?
It works the following way:
SELECT q, count(v.id) FROM Question q JOIN q.votes WHERE <condition> GROUP BY q.id
Another approach would be using an aggregate column like described here:
http://www.doctrine-project.org/projects/orm/2.0/docs/cookbook/aggregate-fields/en#aggregate-fields
精彩评论