Hi,

We have a relationship that looks something like this:

User 1 - * Posts

Posts can have various states, let's say 'DRAFT', 'LIVE', 'DELETED'.

Sometimes, we want to get all of the posts in existence for a user by doing:

user.all_posts

Sometimes, we just want to get posts that are not deleted:

user.open_posts

We opted to do this by specifying the primary_join on the relationship,
thus:

open_posts = relationship("Post", = "and_(User.id==Post.user_id,"ยท
                                  "or_(Post.status=='DRAFT',
Post.status=='LIVE'))")

all_posts = relationship("Post")

(as suggested here:
http://stackoverflow.com/questions/2863786/how-do-i-specify-a-relation-in-sqlalchemy-where-one-condition-requires-a-column
)

This worked, but we now have a problem in some of our processing - when we
use user.open_posts before changes have been sent to the database, all
posts including those deleted are returned.

Putting in session.refresh at various points now seems to do the trick, but
I wanted to ask:

1. Is our approach generally correct as a way of doing filtered
relationships/joins
2. Are session.refresh calls the right way to make it work while changes
are still in memory

Thanks for any ideas,
Ben

-- 
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