php - cakePHP query using find() method -


how can convert query use cakephp's method find() ?

query:

select ch.id, count( du.d_id ) a, sum(du.d_id) b c ch left join du du on du.c_id = ch.id , month( du.created ) = month( now( ) ) left join d d on du.d_id = d.id group ch.id 

$ch->find(     'all',           'fields' => array(                'ch.id','count( du.d_id ) a', 'sum(du.d_id) b'),     'joins'  => array(                       array(                             'table' => 'du',                             'alias' => 'du',                             'type' => 'left',                             'conditions' => array('du.c_id = ch.id , month( du.created ) = month( now( )')),                        array(                             'table' => 'd',                             'alias' => 'd',                             'type' => 'left',                             'conditions' => array('du.c_id = ch.id , month( du.created ) = month( now( )')),     'group' => 'ch.id');           

i haven't tested. more info on cake joins:

http://book.cakephp.org/view/1018/find


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -