On Sunday, September 1, 2013 8:19:24 AM UTC+10, Michael Bayer wrote:

>
> On Aug 31, 2013, at 1:16 AM, gbr <[email protected] <javascript:>> 
> wrote: 
>
> > Could anyone provide some suggestions on where to look in the SQLA code 
> (or even an example, or some general thoughts) for how to perform a 
> `joinedload` as the ORM does it for Core tables 
> > 
> > For performance reasons, I prefer using Core for loading data and do the 
> post-processing manually. 
>
>
> this is a really open-ended question, the answer which depends on a. what 
> are we starting with, i.e. known tables/columns/etc?  or some kind of 
> alternate mapping system?  what are the inputs to the function? and b. what 
> do we get at the end?  a result proxy? some kind of object or series of 
> collections ? 
>

Let me add a bit of information. I assumed the behaviour would be the same 
in ORM (actually, when looking at the docs again I saw it's actually called 
"subquery eager loading", i.e. issuing an additional query upon receiving a 
bunch of table rows which other tables relate to).
The first query I sent is a join of other tables, has a where clause and a 
CTE. The 2nd query also contains a CTE (the same as the 1st). I know the 
columns to join on and can specify them. A result proxy is fine as a result.
 

>
> a joinedload() is just a JOIN (or LEFT OUTER JOIN).  in Core, you just do 
> this: 
>
>         connection.execute(table_a.outerjoin(table_b, table_a.c.id == 
> table_b.c.a_id)) 
>
> so that's a "joinedload".  is that all you need to see ? 
>

Oh, is it that easy? Is this the same for a subquery eager load? I tried to 
use this, but ran into an issue (`CompileError: Multiple, unrelated CTEs 
found with the same name`). I could use just one CTE, as they are the same 
for both queries, but I don't know how to remove it from the subqueried 
(query 1) query.
 

>
> > (or actually an already executed query which has unresolved references 
> which I'd like to load in a subsequent query)? 
>
> that sounds more like a lazyload.... 
>

It should be eager, i.e. I just want to issue 1 queries per nested level.
 

>
>
> as far as the actual code in SQLA, it is built to handle an extremely wide 
> range of scenarios so it's not that simple to follow for someone unfamiliar 
> with the ORM codebase.  It's in sqlalchemy/orm/strategies.py -> 
> JoinedLoader. 
>
>
Yep, I realised that when I was looking at the actual code... 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to