Creating a filtered relationship which excludes soft deleted records

320 views
Skip to first unread message

Amos

unread,
Jun 25, 2012, 7:23:22 PM6/25/12
to sqlal...@googlegroups.com
I have a one-to-many relationship from parent to items. In my Parent class I define the items relationship like so:

items = relationship('Item')

I am using a soft-delete mechanism on items and I'd like to be able to filter this relationship so it only returns active items. It there a mechanism built-in to SQLAlchemy for filtering relationships? Something like this:

items = relationship('Item', filter_by='Item.deleted_at == None')

Michael Bayer

unread,
Jun 26, 2012, 10:43:14 AM6/26/12
to sqlal...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/raEUiUviQNEJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

Reply all
Reply to author
Forward
0 new messages