On Feb 20, 8:59 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> the cleanest and most foolproof way is to join on relationships that have the 
> condition:
>
> related_non_deleted = relationship(Related, 
> primaryjoin=and_(Related.deleted==False, Related.foo_id==id), viewonly=True)

I agree that the explicit approach is the most foolproof.  The main
reason I was trying to avoid it is that, in my case, the condition is
ubiquitous. Thus all of my relationships that look like this

children = relationship(Child)

would have to change to

children = relationship(Child, primaryjoin=and_(Child.deleted==False,
Child.parent_id==id)

Perhaps I could write a custom relationship() to simplify things.
I'll give that a try.  I'll also have to
add .filter(foo.deleted==False) to all top level queries.  Maybe a
custom Session that always answers a query with that filter already
added would be cleaner.  There may ultimately be many queries and many
relationships in this app, and I'm trying to avoid having to remember
(or worse, have someone else remember) to always include the deleted
condition.

Thanks for your help.  I've got a bit of digging to do now.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to