Given the following Model relations:

article <-- HABTM (articles_tags) --> tag

How do I fetch back a list of Tags with the count of associated
Articles?

I've tried (in the Tag Model):

                $data = $this->find("all", array(
                        "fields"=>array(
                                "Tag.id",
                                "Tag.name",
                                "COUNT(Article.id) AS tag_count"
                        ),
                        "conditions"=>array(
                                "Article.published" => 1
                        ),
                        "group" => "Tag.id"
                ));

But that doesn't generate the HABTM join in the SQL:

SQL Error: 1054: Unknown column 'Article.id' in 'field list'
SELECT `Tag`.`id`, `Tag`.`name`, COUNT(`Article`.`id`) AS tag_count
FROM `tags` AS `Tag` WHERE `Article`.`published` = 1 GROUP BY
`Tag`.`id`

Thanks in advance :-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to