[SQLObject] subquery with IN operator

2007-02-25 Thread Daniel Nogradi
Hi list,

I would like to build an SQL query with sqlbuilder that contains
several IN operators but I don't seem to succeed. The model is quite
simple, there are several cities, each city contains a number of
buildings, each building contains a number of floors and each floor
contains a number of rooms. So it's pretty straightforward:

class city(SQLObject):
name = StringCol( )
buildings = MultipleJoin( 'building' )

class building(SQLObject):
name = StringCol( )
complex = ForeignKey( 'city' )
floors = MultipleJoin( 'floor' )

class floor(SQLObject):
name = StringCol( )
building = ForeignKey( 'building' )
rooms = MultipleJoin( 'room' )

class room(SQLObject):
name = StringCol( )
floor = ForeignKey( 'floor' )

Now I would like to have a single SQL query for selecting all distinct
room names in a given city. The problem is that with the above model
both building.q.complex and building.q.floors throw an AttributeError
so I can't use these in a room.select( ) statement together with IN
and my impression so far has been that in such a select statement one
should use these magic 'q' variables.

Any ideas?

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss


Re: [SQLObject] subquery with IN operator

2007-02-25 Thread Oleg Broytmann
On Sun, Feb 25, 2007 at 11:11:54PM +0100, Daniel Nogradi wrote:
 class city(SQLObject):
 name = StringCol( )
 buildings = MultipleJoin( 'building' )
 
 class building(SQLObject):
 name = StringCol( )
 complex = ForeignKey( 'city' )
 floors = MultipleJoin( 'floor' )
 
 class floor(SQLObject):
 name = StringCol( )
 building = ForeignKey( 'building' )
 rooms = MultipleJoin( 'room' )
 
 class room(SQLObject):
 name = StringCol( )
 floor = ForeignKey( 'floor' )
 
 both building.q.complex and building.q.floors throw an AttributeError
...
 Sorry for the typo, building.q.complex should have been building.q.city.

   But there is no city column in building. I would recommend you to
start with foreign keys that exactly match referenced tables:

class building(SQLObject):
name = StringCol( )
city = ForeignKey( 'city' )
floor = MultipleJoin( 'floor' )

   Alas, there is no building.q.floor because MultipleJoin implemented in
SQLObject by backreferencing from the referenced table's ForeignKey.

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

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss