CakePHP nested associations, empty records errors -
i have few tables connected (hasmany) tree: 1 -> 2 -> 3. there few records in table 1, table 2 , 3.
i'm using cakephp fetch data table 1 connected table 2, connected table 3. few records in table 1 don't have connected records in table 2. same in table 2, records don't have connected records in table 3.
for second situation scripts work fine. this: 1 -> 2 -> empty. in first situation, when data looks similar to: 1-> empty -> empty errors table 3 doesn't exist.
is there solution skip errors , pretty formatted association table return query?
$options = array( 'conditions' => array( 'table1.id' => $table1_ids ), 'contain' => array( 'table2' => array( 'conditions' => array( 'id' => $table2_ids ), 'table3' => array( 'conditions' => array( 'date_end >' => date('y-m-d h:i:s') ), 'fields' => array('id'), ), 'fields' => array() ), ), 'fields' => array('id', 'name') ); $this->table1->recursive = -1; $table1 = $this->table1->find('all', $options);
it's not cakephp blame here lack of understanding contain does.
what you're looking left joins, hinted in documentation of contain.
Comments
Post a Comment