On Jul 13, 2008, at 12:54 AM, Kyle Schaffrick wrote:
>
> Er, I think I misread you the first time, this looks like it would
> involve modifying the mapper, to turn "bs" into a Query factory.
> Wouldn't that would break all the rest of the code that treats "bs"
> like
> a collection? Also, would sess.query(A).option(eagerload('bs')) still
> work?
the "query factory" nature of a dynamic relation still supports very
rudimental collection behavior, i.e. append(), remove(), __iter__(),
etc. but yes it doesnt support things like sets or dicts, and every
access to it produces SQL. the eagerload('bs') wouldn't have any
effect.
> Basically what would be ideal in my situation, is if the instrumented
> attributes for relations had some method for providing a loading hint,
> for ex:
>
> a = ses.query(A).first()
>
> # ...sometime later, in another part of the code, I know I'll be
> # iterating over "a.bs" and touching "cs" on each one, so I do:
> instance_option(a, eagerload('cs'))
>
> [ c.blah for c in a.bs ] # load of bs eagerloads cs
>
> As I mentioned, in my situation, the query at the top has no knowledge
> of what class A is, nor whether or not it needs loading options.
that was the non-API method I mentioned earlier. Here's the non-
API way to do it (using 0.5, also not tested):
a = sess.query(A).first()
from sqlalchemy.orm.strategies import LazyLoader
from sqlalchemy.attributes import instance_state
strategy = A.bs._get_strategy(LazyLoader)
state = instance_state(a)
path = (class_mapper(A), 'bs')
strategy._init_instance_attribute(state,
callable_=strategy.setup_loader(state, [eagerload('cs')], path))
the API you mentioned, providing a standalone callable which takes
options, is probably how id go with this one (along the lines of
instance_option(A.bs, a, eagerload('cs')) ). We'd need to build up
some tests in order to add this as an official feature.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---