2010年1月8日星期五

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

Thanks, Victor. It was much simpler than I thought. I didn't know you
could just stack joins like that. Thanks! Perfect.

Corey

On Thu, 07 Jan 2010 01:52:56 +0300, "Victor Farazdagi"
<victor@afcomponents.com> said:
> 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
> >
>

//
Corey H Maass
Gelform Design
Brooklyn, NY
Web design and development for art and business

em corey@gelform.com
ww http://www.gelform.com
ph 646/228.5048
fx 866/502.4861
IM gelform
tw http://twitter.com/coreymaass
fb http://facebook.com/coreymaass

没有评论: