Thank you, found it :)
I was looking at the same spot in the sqlalchemy docs, but somehow missed it ...
The solution is a little bit longer and it does make use of the session object:

session.query(First,
Second).select_from(First.table.join(Second.table, First.c.var ==
Second.c.var)).all()

Is it necessary to use "First.c.var == Second.c.var"?
Is there any code style guide to _forbid_ using directly "First.var ==
Second.var"?

I am going to try using the add_entity way ...

Karol

On Tue, Apr 22, 2008 at 9:36 AM, Gaetan de Menten <[EMAIL PROTECTED]> wrote:
>
>  On Mon, Apr 21, 2008 at 11:51 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> wrote:
>
>  >  I have a question regarding join, I want to join two tables (I have
>  >  not defined any ManyToOne,.. relationship between them and I can't),
>  >  but as a result I want to get an tuple (preferably) with the 2
>  >  correlated rows as objects in it or one of the objects (for example
>  >  the row from the first table). I tried to use something like
>  >
>  >  First.table.join(Second.table, First.var ==
>  >  Second.var).select().execute().fetchall()
>  >
>  >  however this returns a list of tuples (First.id, First.var, ...,
>  >  Second.id, ...)
>  >  I tried also this
>  >
>  >  First.query.filter(First.var == Second.var).all()
>
>  I think what you are looking for is "select_from". See:
>  http://www.sqlalchemy.org/docs/04/ormtutorial.html#datamapping_joins
>  and
>  
> http://www.sqlalchemy.org/docs/04/sqlalchemy_orm_query.html#docstrings_sqlalchemy.orm.query_Query
>
>  You might also be interested in "add_entity", though I've never used
>  it myself so I don't know for sure.
>
>
>  >  on the test database it's acceptable, the real tables will be quite
>  >  larger => JOIN would be faster ...
>
>  How so? I might not be fully awake yet, but I'd expect any decent
>  database will have the same performance for an inner join as for a
>  where statement, at least when only two tables are involved...
>
>  --
>  Gaƫtan de Menten
>  http://openhex.org
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to