paginator - CakePHP don't include records whose contained model is empty -
so current paginate settings this:
public $paginate = array( 'limit' => 30, 'contain' => array( 'model1' => array( 'fields' => array('id') ), 'model2' => array( 'conditions' => array( 'model2.type' => 'sometype' ), 'model3' => array( 'fields' => array('somefield') ) ) ) ); what want achieve when contained model2 happens empty (there no model2 type 'sometype'), record of model0 (the parent of model1 , model2) should not included in returned array of $this->paginate('model0');.
how achieved?
i'm not sure if can achieved containable behavior. know can manual joins (disclaimer: may off in query, since haven't tested it):
$results = $this->model0->find('all', array( 'conditions' => array( 'model2.id <>' => null, ), 'joins' => array( array( 'table' => 'model2', 'alias' => 'model2', 'type' => 'left', 'conditions' => array( 'model2.type' => 'sometype', 'model2.model0_id = model0.id', ), ), array( 'table' => 'model3', 'alias' => 'model3', 'conditions' => array( 'model3.model2_id = model2.id' ), ), ), ));
Comments
Post a Comment