On May 14, 2011, at 10:12 PM, Hector Blanco wrote:

> What I'd like is something like:
> class Whatever(declarativeBase):
>       [ . . . ]
>       def getAllowedUserGroups(self):
>               session = Database.Session()
>               query = 
> session.query(UserGroup.UserGroup).filter(UserGroup.UserGroup.in_(self.allowedVisibilizers))
>               return query.all()
> 
> (but obviously, UserGroup is a class and doesn't have an in_)
> 
> Of course, I could always get all the "allowedVisibilizers" and remove
> the Users from the returned value, but I was trying to make it a
> little bit optimized than that and avoid unnecessary calls to the
> database.
> 
> Any hint will be very appreciated. Thank you in advance!

usually you'd want to select UserGroup objects and filter on the rows in the 
association table for allowedVisibilizers.   you can reference the "secondary" 
table directly.

You can probably also take a shortcut and use with_parent() which should do the 
same thing:

session.query(UserGroup).with_parent(self, "allowedVisibilizers").all()



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