Skip to content Skip to sidebar Skip to footer

Sqlalchemy: Filter Many-to-many Joinedload

I have the current table setup for a many to many association between 'words' and 'phrases': association_table_wp = Table('words_phras', Base.metadata,

Solution 1:

I think contains_eager() is what you're looking for:

words = db_session.query(Word).\
    join(Word.phrases).\
    options(contains_eager(Word.phrases)).\
    filter(Word.id.in_(word_ids)).\
    filter(Phrase.active == True)

Post a Comment for "Sqlalchemy: Filter Many-to-many Joinedload"