finding items that don't contain, or don't have, an item is always via EXISTS, 
which is easiest using any()/has():

Session.query(Messages).filter(Messages._from_user == 
1).filter(~Messages.user.has(User.id==1)


On Sep 17, 2010, at 9:04 AM, Dobrysmak wrote:

> Okay, i have got a stupid question.
> i have got something like this:
> 
> result = Session.query(Messages).filter(
>                  Messages.from_user == 1).filter(
>                        User.id != 1).all()
> 
> This query is supposed to get all the messages ( Messages table) that
> have the senders id (from_user) but select ONLY this messages that are
> connected to all users except user with id = 1.
> This tables are many-to-many( Messages, Messages_Users, Users ). The
> relationship is set correctly.
> 
> Is this even possible? ;-)
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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