I have two models in cakephp, Link and Vote.
I want to have the sum of the votes for every link in my Link model. Here is a print of my findAll function :
[1] => Array
(
[Link] => Array
(
[id] => 1
[url] => http://www.google.com
[date_added] => 2010-08-19 11:36:56
[valid] => 1
)
[Vote] => Array
(
[0] => Array
(
[link_id] => 1
[user_id] => 0
[vote] => 3
)
[1] => Array
(
[link_id] => 1
[user_id] => 4
[vote] => 4
)
)
)
What I would like to have is this (note the votes attribute) :
[1] => Array
(
[Link] => Array
(
[id] => 1
[url] => http://www.google.com
[date_added] => 2010-08-19 11:36:56
[valid] => 1
[votes] => 7
)
[Vote] => Array
(
[0] => Array
(
[link_id] => 1
[user_id] => 0
[vote] => 3
)
[1] => Array
(
[link_id] => 1
[user_id] => 4
[vote] => 4
)
)
)
But I have no idea where I'm supposed to do the SUM of the votes.