Skip to content

Instantly share code, notes, and snippets.

@henrikbjorn
Created February 7, 2009 10:48
Show Gist options
  • Save henrikbjorn/59849 to your computer and use it in GitHub Desktop.
Save henrikbjorn/59849 to your computer and use it in GitHub Desktop.
<?php
class Forum extends AppModel
{
var $actsAs = array('Containable');
var $hasMany = array(
'Forums' => array(
'className' => 'Forum',
'foreignKey' => 'parent_id',
'fields' => array(
'Forums.*',
'(SELECT sum(ForumPost.comment_count) FROM forum_posts as ForumPost WHERE ForumPost.forum_id = Forums.id GROUP BY ForumPost.forum_id) AS forum_post_comment_count',
),
),
);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment