Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLAlchemy Relationship Filter?

Can I do

table.relationship.filter( column = value )

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

like image 500
Timmy Avatar asked May 04 '10 17:05

Timmy


2 Answers

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.

like image 182
Denis Otkidach Avatar answered Nov 02 '22 14:11

Denis Otkidach


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.

like image 21
nosklo Avatar answered Nov 02 '22 14:11

nosklo