Thank you for pointing this out!

I did not realize that it has such a consequencies, though it is perfectly
logical. My bad. All joinedloads are part of the main query now, as they should.

Also, ignore my remark about Tag info being not loaded. When there actually are
any tags, they get loaded as expected (though I stil don't understand why the
SQL is different in both cases).

The only thing remaining is that the following subqueryloads are loaded in
isolation:

> subqry -> /subject/contacts/
> subqry -> /subject/contacts/contact_personal/
> subqry -> /subject/contacts/contact_personal/contact_address/
> subqry -> /subject/contacts/contact_personal/permanent_address/

And I just realized / understood why! Because subqueryload uses JOIN and all
above relations can be NULL. Is this correct?

I have two types of contacts, personal and corporate. The above loads:
* ALL Subject.contacts (i.e. personal AND CORPORATE)
* The rest only work with the personal.


Thank you very much! It has been enlightening as always,

Ladislav Lenart


On 26.9.2013 16:13, Michael Bayer wrote:
> 
> On Sep 26, 2013, at 9:30 AM, Ladislav Lenart <lenart...@volny.cz> wrote:
> 
>>
>> Your thoughts on this? Do you see anything suspicious?
>>
>> BTW the new system for 0.9 looks very nice!
> 
> OK I only started reading the first few queries, but immediately what I think 
> is causing confusion here is that your loading options are conflicting with 
> each other, so the joinedload() you're looking for at the top is being 
> partially cancelled out:
> 
> session.query(Partner).filter(
>    Partner.id.in_(win)
> ).options(
>    joinedload(Partner.subject, innerjoin=True),
>    joinedload(Partner.subject, Subject.subject_personal, innerjoin=True),
>    joinedload(Partner.subject, Subject.subject_personal, 
> SubjectPersonal.address),
>    subqueryload(Partner.subject, Subject.contacts),
>    subqueryload(Partner.subject, Subject.contacts, Contact.contact_personal),
>    subqueryload(Partner.subject, Subject.contacts, Contact.contact_personal, 
> ContactPersonal.contact_address),
>    subqueryload(Partner.subject, Subject.contacts, Contact.contact_personal, 
> ContactPersonal.permanent_address),
>    subqueryload_all(Partner.subject, Subject.tag_subjects, TagSubject.tag),
>    subqueryload_all(Partner.partner_regions),
> )
> 
> 
> the directive subqueryload_all(Partner.subject, Subject.tag_subjects, 
> TagSubject.tag) is after the joinedloads you have above, so the 
> joinedload(Partner.subject) is cancelled out by that, hence all the 
> additional joinedload() that build on top of that is pushed out to be part of 
> the subqueryloads.   
> 
> you can read these directives just like paths.  The "path" is a unique key in 
> a dictionary.  as the loading traverses along each relationship, it looks up 
> the path, and the kind of loader called for.  the above is the equivalent of:
> 
> joined -> /subject/
> joined -> /subject/subject_personal/
> joined -> /subject/subject_personal/address/
> subqry -> /subject/contacts/
> subqry -> /subject/contacts/contact_personal/
> subqry -> /subject/contacts/contact_personal/contact_address/
> subqry -> /subject/contacts/contact_personal/permanent_address/
> subqry -> /subject/   (overrides the joined)
> subqry -> /subject/tag_subjects/
> subqry -> /subject/tag_subjects/tag/
> subqry -> /partner_regions/
> 
> 


-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
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