On Fri, Dec 18, 2015 at 1:20 AM, Jonathan Vanasco <[email protected]>
wrote:
> I'm trynig to use association_proxy to map a collection of items through
> an intermediary table
>
> I'm running into a problem where I can't figure out a way to eagerload the
> collection through the extension.
>
> if i do:
> query.options(joinedload('to_items', 'to_items.item'))
>
> I can loop through to_items and item fine.
>
> When I loop '.items', I hit the DB.
>
> I tried eagerloading the 'items' relation, and that didn't work either.
>
> I must be using the association_proxy wrong. Does anything here jump out
> to others?
>
>
>From what I understand, joinedload('to_items', 'to_items.item') configures
joined loading on the to_items.item relationship, but not on the to_items
one. This is mentioned in the 0.8 docs:
http://docs.sqlalchemy.org/en/rel_0_8/orm/loading.html#sqlalchemy.orm.joinedload
# joined-load the "keywords" collection on each "Item",
# but not the "items" collection on "Order" - those
# remain lazily loaded.
query(Order).options(joinedload(Order.items, Item.keywords))
# to joined-load across both, use joinedload_all()
query(Order).options(joinedload_all(Order.items, Item.keywords))
0.9 introduced a new API, and I think this subtlety in the old API was lost
from the docs. The new API would look something like:
query.options(joinedload('to_items').joinedload('item'))
http://docs.sqlalchemy.org/en/rel_1_0/orm/loading_relationships.html#loading-along-paths
Hope that helps.
Simon
--
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.