On Sep 28, 2008, at 6:38 PM, Ksenia wrote:
>
> Hi list,
>
> I can't figure out a very simple thing. All I want is to do this
> query:
>
>
> select table1.A, table2.B, table3.C from table1, table2, table3 where
> table1.foreignkey2 = table2.primarykey and table1.foreignkey3 =
> table3.primarykey;
>
> When rendering results, I want to be able to refer to the properties
> of the joined tables:
>
>
> <td>${row.A}</td>
> <td>${row.table2.B}</td>
> <td>${row.table3.C}</td>
>
> My mapper looks like:
>
> mapper(Table1, table1,
> properties={
> 'table2':relation(Table2, lazy=False,
> uselist=False),
> 'table3':relation(Table3, lazy=False,
> uselist=False)
> }
> )
>
>
> When I run it it creates a query with tables joined via LEFT OUER
> JOIN.
>
> How can I non-lazy (with minimal number of queries) join tables,
> without LEFT OUTER JOIN? But still be able to refer to the properties
> of joined tables?
remove the lazy=False from each relation(); leave eager loading as an
option which you'd enable for an individual Query if desired.
For your SQL to be generated, say:
session.query(Table1.A, Table2.B,
Table3
.C
).filter
(Table1
.foreignkey2
==Table2.primarykey).filter(Table1.foreignkey3==Table3.primarykey)
To create the equivalent using JOIN while taking advantage of the
relations:
session.query(Table1.A, Table2.B,
Table3.C).join(Table1.table2).join(Table1.table3)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---