2010年1月6日星期三

Re: [fw-db] Join within a join in zend_db_select

Zend_Db_Select allows you to define joins:

$select = new Zend_Db_Select($db); $select->     from('cds', array('*'))->     joinInner('artists', 'artists.Id = cds.Artist', array('artists.Name', 'artists.City'))->     joinLeft('countrys', 'countrys.Id = artists.Country', array('Country' => 'countrys.Name'));  
More on this http://framework.zend.com/manual/en/zend.db.select.html#zend.db.select.building.join

Victor

P.S. If you are using extension of Zend_Db_Table_Abstract, you'd need to setIntegrityCheck(false), in order to join tables.

gelform wrote:
I'm creating a select to hand to zend_paginator. My SQL request has a join within a join and I'm not sure how to build a select with this.  I want to get all CD's, the artist of the cd, and the city and country of the artist.  SELECT cds.*, artists.Name, artists.City, countrys.Name as "Country" FROM cds INNER JOIN artists ON cds.Artist=artists.Id LEFT JOIN countrys ON artists.Country=countrys.Id;  I've been referencing the documentation but nothing I've tried has worked.  http://framework.zend.com/manual/en/zend.db.select.html  Thanks!  Corey   

没有评论: