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?




    class Collection()
        __tablename__ = 'collection'
        id = sa.Column(sa.Integer, primary_key=True)
        name = sa.Column(sa.Unicode(32), nullable=False)

        to_items = sa.orm.relationship("item_2_collection",
                                        
primaryjoin="collection.id==Item2Collection.collection_id",
                                        back_populates='collection',
                                       )

        items = association_proxy('to_items', 'item')


    class Item():
        __tablename__ = 'item'
        id = sa.Column(sa.Integer, primary_key=True)
        name = sa.Column(sa.Unicode(32), nullable=False)


    class Item2Collection()
        __tablename__ = 'item_2_collection'
        __primarykey__ = ['item_id', 'collection_id']
        item_id = sa.Column(sa.Integer, sa.ForeignKey("item.id"), 
nullable=False, primary_key=True)
        collection_id = sa.Column(sa.Integer, 
sa.ForeignKey("collection.id"), nullable=False, primary_key=True)

        # relations
        item = sa.orm.relationship("Item",
                                  
 primaryjoin="Item2Collection.item_id==Item.id",
                                   uselist=False,
                                   )
        collection = sa.orm.relationship("Collection",
                                        
 primaryjoin="Item2Collection.collection_id==Collection.id",
                                         back_populates='to_items',
                                         uselist=False,
                                         )

-- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to