this depends on if you want Episodes that only have shows which are bound to that user. this would be:
q = s.query(Episode, Show)\ .join(Episode.shows).\ .filter(Episode.airdate.between(date1, date2))\ .filter(~Show.users.any(User.id==2)) to get *all* episodes, you'd have to use a subquery: subq = s.query(Show).filter(~Show.users.any(User.id==2)).subquery() show_alias = aliased(Show, subq) q = s.query(Episode, show_alias)\ .join((show_alias, Episode.shows)).\ .filter(Episode.airdate.between(date1, date2)) Domen Kožar wrote: > > models: User, Show, Episode > > Show 1-----n Episode > User n------n Show > > so: shows can have multiple episodes and different users can have > different shows > > > I want to construct a query that will: > > - check if episode dates to specific date > - join all shows on that episode > - filter out shows that are not bound to specific user > > the query that is not working correctly is: > > AShow = aliased(Show) > q = s.query(Episode, AShow)\ > .filter(Episode.airdate.between(date1, date2))\ > .filter(User.userID == 2)\ > .join(User.relShows)\ > .join(AShow) > > (User.relShows is the n-n relation to Shows that lists all shows which > one user posseses) > > If I haven't explained myself enough, please say so. I have no idea > where I'm failing:) > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---