I am trying to select data using LEFT join in cakephp, here how can i use more than two tables for LEFT join.Here iam creating LEFT join between two tables news_feeds and news_feed_likes.i want to introduce two more tables here, NewsFeedComments and newsfeed_likes_comments.How can i do this?
Thanks for your help
$this->paginate = array(
'conditions' => array('NewsFeed.group_id'=>$groupdata['Group']['id'],'NewsFeed.status'=>'A'),
'joins' => array(
array(
'alias' => 'newslikes',
'table' => 'news_feed_likes',
'type' => 'LEFT',
'conditions' => array(
'newslikes.news_feed_id = NewsFeed.id',
'newslikes.user_id'=>$this->Auth->user('id'),
'newslikes.status'=>'1',
),
),
array(
'alias' => 'newscommentslikes',
'table' => 'news_feed_comments_likes',
'type' => 'LEFT',
'conditions' => array(
'newscommentslikes.news_feed_comment_id = NewsFeedComment.id',
'newscommentslikes.user_id'=>$this->Auth->user('id'),
'newscommentslikes.status'=>'1',
),
),
),
'fields' => array(
'IFNULL(newslikes.user_id,0) AS likestatus',
'NewsFeed.id',
'NewsFeed.posted_message',
'NewsFeed.created',
'NewsFeed.user_id',
'NewsFeed.status',
'NewsFeed.newslike',
'IFNULL(newslikes.status,0) AS status',
),
'order' => array('NewsFeed.created' => 'desc'),
);
$this->set('newsfeed', $this->paginate( $this->NewsFeed ) );
'joins' => array(array(..first join..), array(..second join..), ..., array(.. nth join..));Have you tried just adding more arrays to the joins array? - iso27002