On Mon, Mar 10, 2008 at 08:57:35AM -0700, Daniel Fetchinson wrote:
> On Mon, Mar 10, 2008 at 3:12 AM, Oleg Broytmann <[EMAIL PROTECTED]> wrote:
> > On Sun, Mar 09, 2008 at 08:52:28PM -0700, Daniel Fetchinson wrote:
> > > class zoo( SQLObject ):
> > >     cages = MultipleJoin( 'cage' )
> > >
> > > class cage( SQLObject ):
> > >     zoo = ForeignKey( 'zoo' )
> > >     animals = MultipleJoin( 'animal' )
> > >     properties = RelatedJoin( 'property' )
> > >
> > > class animal( SQLObject ):
> > >     cage = ForeignKey( 'cage' )
> > >     properties = RelatedJoin( 'property' )
> > >
> > > class property( SQLObject ):
> > >     animals = RelatedJoin( 'animal' )
> > >     cages = RelatedJoin( 'cage' )
> > >
> > >
> > > What would be the select call for selecting all properties for a given
> > > zoo instance?
> >
> >    SQLObject cannot automagically construct such a comple SQL query. You
> > can do it in Python:
> >
> > z = zoo.get(id)
> > zoo_properties = []
> > for c in z.cages:
> >   for a in c.animals:
> >      for p in a.properties:
> >         zoo_properties.append(p)
> 
> Thanks, this is the approach I had so far, but I thought some clever join
> construction would do it if done right.

   Yes, it is possible, but in a rather complex way. You have to declare
all intermediate tables for RelatedJoins and manually construct a complex
join like

property.select(
   (property.q.id == property_animal.q.property_id) &&
   (animal.q.id == property_animal.q.animal_id) &&
   (animal.q.cage_id == cage.q.id) &&
   (cage.q.zoo_id == z.id)
)

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            [EMAIL PROTECTED]
           Programmers don't die, they just GOSUB without RETURN.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to