Search code examples
phpmysqlzend-frameworkjoinzend-db-select

zend_db_select join using 3 or more tables


So Zend_db_select has the methods

  `joinUsing(table, join, [columns]) and joinInnerUsing(table, join, [columns])`

  `joinLeftUsing(table, join, [columns])`

  `joinRightUsing(table, join, [columns])`

  `joinFullUsing(table, join, [columns])`

etc

but what if you want to join 3 or more tables (eg for a many to many association)....eg: this query:

 SELECT * FROM (j LEFT JOIN e ON j.id = e.eee) LEFT JOIN w ON w.www = e.id

how would you go about doing this with zend_db_select


Solution

  • Try doing ... but i am not so sure works with two fields but have not tried with 3 fields

    $dbmodel->select(false)
        ->setIntegrityCheck(false)
        ->from(array('t1' => 'table1'))
        ->joinLeft(array('t2' => 'table2'),                                             
            't1.somefeild = t2.somefeild')
        ->joinLeft(array('t3' => 'table3'),                                             
            't2.somefeild = t3.somefeild')
    

    you try to build query, and also you can check query by die((string)$select)