SQLAlchemy Relationship Filter?

Question:

Can I do

table.relationship.filter( column = value )

to get a subset of rows for relationships? and the same for order_by?

Asked By: Timmy

||

Answers:

According to the relationship() documentation, you can use order_by keyword argument with relationships, to set the order that will be returned. On the same page, it mentions that you can also use primaryjoin keyword argument to define extra join parameters. I think that can be used for the filter you want.

Answered By: nosklo

relationship() with lazy='dynamic' option gives you a query (AppenderQuery object which allows you to add/remove items), so you can .filter()/.filter_by() and .order_by() it.

Answered By: Denis Otkidach
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.