Hmm.... maybe I'm missing something. Perhaps someone else can jump in,
and show me what I'm missing?

When I take your code, and execute the following 5 cases:

    CASE A: no 'subquery' on relationship, 'subqueryload' on query
    CASE B: 'subquery' on relationship, no 'subqueryload' on query
    CASE C: no 'joined' on relationship, 'joinedload' on query
    CASE D: 'joined' on relationship, no 'joinedload' on query
    CASE E: no 'joined' or 'subquery' on relationship, no 'joinedload'
or 'subqueryload' on query

1) The queries in cases A & B are equal (exactly 2 queries each)
2) The queries in cases C & D are equal (exactly 1 query each)
3) Case E is completely lazy, there are exactly 1 + N queries

Here are the notes I kept, as I tested those cases:

    http://pastebin.com/hx0Kj4An

Martin: perhaps create a new pastebin that shows exactly what you're
doing (including table/engine/session creation, data population, etc),
so that I have a better chance of seeing what you're seeing?

    http://pastebin.com/mcum0c7Q

--diana

On Thu, Nov 22, 2012 at 6:09 AM, Martin84 <steko...@googlemail.com> wrote:
> Hi Diana,
>
> thank you for your help, but unfortunately my problem still exists.
> In my case the lazy attribute for the myChildren relationship has absolutely
> no effect!
> At this point one more information is important: I build and populate the
> database with one session, and then open a new session and call
> showDatabase.
> If you populate the database with one session, and then call showDatabase
> with the same (now not empty) session,
> then the instances are already in the session and sqlalchemy don't fire new
> queries for access to the myChildren attribute of human.
> So, it is important to call showDatabase with an empty session to reproduce
> my issue.
>
> One more information could be important:
> If I load a woman instance and access myChildren with:
>
> woman = session.query(Woman).one()
> print woman.myChildren
>
> then sqlalchemy emits an extra sql query on the access to myChildren and
> ignore my lazy='subquery' or lazy='joined' parameter for the mychildren
> relationship configuration.
> But if I modify the query like this:
>
> woman = session.query(Woman).options(subqueryload('myChildren')).one()
> print woman.myChildren
>
> then sqlalchemy load the woman and all children at once! Exactly what I
> need.
> But this makes completely no sense to me, i thought that subqueryload() just
> overload the load strategie for a relationship.
> So myChildren = relationship('Child', secondary=link_table, lazy='subquery')
> and subqueryload('myChildren') should be equivalent.
> Why is there a difference?
>
>
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sqlalchemy/-/GponYdm2PLsJ.
>
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to