mysql - CakePHP LEFT JOIN on multiple tables with condition -


i want use cakephp form left join. see cakephp book - section on joining tables

$options['joins'] = array(     array('table' => 'channels',         'alias' => 'channel',         'type' => 'left',         'conditions' => array(             'channel.id = item.channel_id',         )     ) ); $item->find('all', $options); 

except left join has dependent table conditions. in mysql join looks this

left join (     channels channel          inner join regions region on ( region.id = channel.region_id , region.id=1 ) ) on channel.id = item.channel_id 

can same thing in cakephp 2.0 using $options['joins'] syntax?

so after bit of fiddling, discovered "trick" in cakephp. according sql explain, faster join using sub-query force conditions on left join table

$options['joins'] = array(     array('table' => '(channels `channel` inner join regions `region`                       on ( `region`.id = `channel`.region_id , `region`.id=1 ))', //        'alias' => 'channel',  // alias 'included' in 'table' field         'type' => 'left',         'conditions' => array(             'channel.id = item.channel_id',         )     ) ); $item->find('all', $options); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -