Thread: [SQLObject] Selecting from JOINed tables
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <spa...@ei...> - 2006-04-19 00:10:48
|
Hi, I'm new to SQLObject, having been taken here via TurboGears. The SQL equivalent of what I'm looking to do in SQLObjects is: SELECT Book.title ,Book.category ,Author.name FROM Book INNER JOIN Author ON Book.id = Author.id ; I've been through the documentation and all the examples of JOINS just have results from a single table. Regards & thanks Mike ----------------------------------------------------------------- Find the home of your dreams with eircom net property Sign up for email alerts now http://www.eircom.net/propertyalerts |
From: Oleg B. <ph...@ma...> - 2006-04-19 07:20:46
|
On Wed, Apr 19, 2006 at 01:10:36AM +0100, spa...@ei... wrote: > I've been through the documentation and all the examples of JOINS just > have results from a single table. JOINs can use as many tables as you want. Examples: Stright join: Table1.select(AND(Table1.q.id==Table2.q.t1_id, Table2.q.name=="value")) LEFT JOIN: Table1.select(join=LEFTJOIN(Table2, Table3)) Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Mike <spa...@ei...> - 2006-04-20 00:05:14
|
Oleg Broytmann <phd <at> mail2.phd.pp.ru> writes: > > On Wed, Apr 19, 2006 at 01:10:36AM +0100, spamfree <at> eircom.net wrote: > > I've been through the documentation and all the examples of JOINS just > > have results from a single table. > > JOINs can use as many tables as you want. Examples: > > Stright join: > Table1.select(AND(Table1.q.id==Table2.q.t1_id, Table2.q.name=="value")) > > LEFT JOIN: > Table1.select(join=LEFTJOIN(Table2, Table3)) > > Oleg. Hi, I have used both examples in interactive Python shell with debug turned on ("postgres://mike:@localhost/mike?debug=1&debugOutput=1"). Selected fields are only returned from the first table. Here's an example. I have 2 simple tables with telephone call data. I want to select all fields from both tables. So i run the following >>> result = Call.select(AND(Call.q.id == Make.q.callsID, Call.q.code == "M")) >>> result[1] 1/Select : SELECT call.id, call.date_time, call.duration, call.code FROM make, call WHERE ((call.id = make.calls_id) AND (call.code = 'M')) LIMIT 1 OFFSET 1 The output I'm looking for is something like SELECT call.col1, call.col2 .... call.coln, make.col1 ... make.coln FROM make, call WHERE ((............... Thanks Mike |
From: Oleg B. <ph...@ma...> - 2006-04-20 08:51:03
|
On Thu, Apr 20, 2006 at 12:00:41AM +0000, Mike wrote: > The output I'm looking for is something like > SELECT call.col1, call.col2 .... call.coln, make.col1 ... make.coln FROM make, > call WHERE ((............... SQLObject manipulates with *objects*. If you have a table and do MyTable.select() SQLObject fetches the table's data and only the table's data. It fetches only the table's data even for joins. Where do you expect SQLObject put those exccessive columns and in what format? If you want a generic SELECT use sqlobject.sqlbuilder.Select(). Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |