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:
Comments
Post a Comment