On Sat, 12 Jul 2008 16:02:15 -0400
Rick Morrison <[EMAIL PROTECTED]> wrote:
> Suppose you have a list result of a simple query:
>
> vector = S.query(MappedObj).filter(foo).all()
>
> and assume "MappedObj" has a simple relation "children", each of those in
> turn having a simple relation "grandchildren". It would be nice to say
> something like
>
> S.vectorload(vector, 'children.grandchildren')
>
> and have *all* the children + grandchildren loaded for each item in
> 'vector'.
This would definately work for what I'm trying to do, although I don't
specifically need support for a sequence of instances. Supporting
sequences does seem more general, were not for it being harder to
implement.
<handwaving>
One would think the DBMS could simply implement lengthy IN clauses by
making a single-column temporary table out of the set of values and then
joining against it. Seems silly that it needs quadratic-time for IN and
much less for a join, when they're logically the same thing.
</handwaving>
On Sat, 12 Jul 2008 22:50:19 -0400
Michael Bayer <[EMAIL PROTECTED]> wrote:
> You can do it when the Query first happens, but have the eagerload
> operation delayed until the lazyload. the "eagerload()" query
> option will plant itself inside the lazy loader and take effect when
> the lazy load occurs, if that's how its set up.
>
> assume A->bs->B->cs->C
>
> a = sess.query(A).options(eagerload('cs')).first()
> print a.bs[0].cs # will lazyload "b" eagerloading "cs"
>
> This same idea takes effect if you just say "lazy=False" when you
> declare the "cs" relation on "B".
Right, I'm aware of this API and would be using it except for that,
where the query happens I don't actually know if I want it or not.
I should point out that what is making this such a difficult problem is
the fact that this function that does the querying doesn't a priori know
what class it's going to be querying for, I pass that in as a parameter.
Thus, hardcoding eagerload options into the function would involve some
reflection and special case complexity that I would prefer to avoid.
> To setup the eagerness of "cs" at the exact point of lazy load, the
> public API that allows this is via "lazy='dynamic'", which would
> allow:
>
> a = sess.query(A).first()
> print a.bs.option(eagerload('cs')).first()
>
> But that changes the "lazyness" of "bs" considerably.
This seems like it might be pointing to a solution, but, what do you
mean by the last statement?
> Yet another option would be an API that allows the "eagerload('cs')"
> option to be embedded into the lazy loader present on "A.bs". This
> is possible right now but you'd be calling upon non-public APIs to do
> it.
I don't think I need this if I'm able to set up the eagerload of "cs"
having only an instance of "A", since the very next thing that happens
is I access "A.bs" and trigger it's loader anyway.
-Kyle
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---