Hi, i'm trying to solve a problem using the cakephp modeling. I have 3 tables: posts, comments and tags, where
- one post have 0 or many comments - one post have one or many tags my physical tables structure is: posts (*id, name, text, date_created) tags(*id,name) comments(*id,post_id, text, username) posts_tags(*post_id,*tag_id) when i list all posts by a specific tag (http://localhost/posts/tag/ cinema) i want to a have a list of posts with all Posts fields and the sum of comments per post, for that in the tags model i put the following association: var $hasAndBelongsToMany = array('Posts' => array( 'className' => 'Posts', 'joinTable' => 'posts_tags', 'foreignKey' => 'tag_id', 'associationForeignKey' => 'post_id', 'conditions' => '', 'order' => '', 'limit' => '', 'uniq' => '', 'finderQuery' => 'SELECT `Posts`.`id`,`Posts`.`name`, `Posts`.`text`,`Posts`.`date_created`, count(`Comments`.`id`) FROM `posts` AS `Posts` LEFT JOIN `comments` as `Comments` ON (`Comments`.`post_id`=`Posts`.`id`) JOIN `tags` as `Tags` ON (`Tags`.`id`={$__cakeID__$}) JOIN `posts_tags` as `posts_tags` ON (`posts_tags`.`post_id`=`Posts`.`id` AND `posts_tags`.`tag_id`=`Tags`.`id`) GROUP BY `Posts`.`id` ORDER BY `Posts`.`date_created` DESC', 'deleteQuery' => '', 'insertQuery' => '' ) ); the query used in the finderQuery returns the pretended fields in mysql and cake debug, but the returned array is empty!: $this->set('posts', $this->Weblog->Tags->find('all', array('conditions' => array('Tags.name' => $this->Weblog->tag_id)))); posts will return: Array ( [0] => Array ( [Tags] => Array ( [id] => 5 [name] => apple [description] => ) [Posts] => Array ( ) ) ) i can solve the problem using the query method but i think i'm doing something wrong, so waiting for any advice. Regards Paulo Gomes --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
