문제

Is there a way to load calculated values into 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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top