开发者

Cakephp SUM of related field

I'm fairly new to cakephp, I need to find the SUM of a one-to-many related table inside a cakephp query.

I have table Users and table Invoices

I want a total sum of the Invoices that belong to the user when I do a find on the Users table. The result I'm looking for is to show users and aggregate totals of invoices.

I've searched and it looks like cakephp 1.3 has a feature called virtualfields, but the app I'm working on is cake 1.2... I'm not sure I want to chance an upgrade of the framework to 1.3.

Is there a way to ac开发者_Python百科complish the same thing in 1.2?


Try something like this in your find (make the appropriate changes):

array('fields' => array('sum(Model.quantity) AS total')

Hope it helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜