开发者

Can Doctrine2 load calculated values?

开发者 https://www.devze.com 2023-01-26 00:42 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消