$markers = $this->Post->find(‘all’, array( ‘joins’ => array(
array(
‘table’ => ‘cp_user’,
‘alias’ => ‘users’,
‘type’ => ‘left’,
‘foreignKey’ => false,
‘conditions’=> array(‘Post.postauthor = users.id’)
)
),
‘conditions’=>’Post.poststatus = 1’,
‘fields’=>array(‘Post.postid’,
‘Post.postdate’,
‘Post.posttitle’,
‘Post.postmessage’,
‘Post.poststatus’,
‘Post.commentstatus’,
‘Post.commenttotal’,
‘Users.id’,
‘Users.firstname’
)
)
);
$this->set(‘cp_post’,$markers);
This will generate the below query in mysql
—————————————————-
SELECT `Post`.`postid`, `Post`.`postdate`, `Post`.`posttitle`, `Post`.`postmessage`, `Post`.`poststatus`, `Post`.`commentstatus`, `Post`.`commenttotal`, `Users`.`id`, `Users`.`firstname` FROM `cp_posts` AS `Post` left JOIN cp_user AS `users` ON (`Post`.`postauthor` = `users`.`id`) WHERE `Post`.`poststatus` = 1
Vinod Ram has been in Software Industry since 2006 and has experience of over 16 years in Software Development & Project Management domain specialised majorly in LAMP stack & Open Source Technology, building enterprise level Web based Application, Large Database driven and huge traffic Websites and Project Management.
He loves to write information articles and blog to share his knowledge and experience with the outside world and help people to find solution for their problems.