Hello
I'm coding this reddit-like clone and so far, so good, just I want to
show how many ups and how many downs are by post in the index.
Something like this:
Up (20) | Down (3) This is the first title
Up (10) | Down (10) Second title here
Up (5) | Down (6) Third title!
A findAll will get me the Post data and then I'll just have to make a
hasOne relationshi with a COUNT, right? It would be something like
this:
$this->bindModel(array(
"hasMany" => array(
"VoteNeg" => array(
"className" => "Votes",
"fields" => array("COUNT(VoteNeg.id)"),
"conditions" => array("VotoNeg.value" => 0)
),
"VotePos" => array(
"className" => "Votes",
"fields" => array("COUNT(VotePos.id)"),
"conditions" => array("VotePos.value" => 1)
)
)
));
The thing is, this COUNTs the total votes for all the three records.
SELECT COUNT(`VotoNeg`.`id`), `VotoNeg`.`propuesta_id` FROM `votos` AS
`VotoNeg` WHERE `VotoNeg`.`valor` = 0 AND `VotoNeg`.`propuesta_id` IN
(2, 3, 1)
I'm using hasMany as hasOne oddly just returns one record, and
includes every vote, regardless of which post it belongs to.
I think I have to use DISTINCT, but I've tried and still won't work
the way it should.
Am I missing something?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---