[sqlalchemy] Re: Getting instances that contains other instances in an N:M relationship

2011-03-17 Thread Hector Blanco
Got it: query = session.query(Store.Store) query = query.join('userGroups', 'users') query = query.filter(User.User.id == int(userId)) print str(query.all()) From the examples inside the sqlalchemy egg (http://prdownloads.sourceforge.net/sqlalchemy/SQLAlchemy-0.6.6.tar.gz?download) In the

[sqlalchemy] Re: Getting instances that contains other instances in an N:M relationship

2011-03-16 Thread Hector Blanco
Cr*p!... 5 minutes after writing, I got it: query = session.query(Store.Store).select_from(join(Store.Store, UserGroup.UserGroup, Store.Store.userGroups)).filter(UserGroup.UserGroup.id == int(userGroupId)) http://www.sqlalchemy.org/docs/orm/tutorial.html#querying-with-joins Well... it may help

[sqlalchemy] Re: Getting instances that contains other instances in an N:M relationship

2011-03-16 Thread Hector Blanco
Hello everyone! I am reopening that because now I want to go an step further... And I'm having troubles. Let's say I have an Store class that has a relationship pointing to UserGroup that has a relationship pointing to Users. I'm trying to create a method getStoresByUserId(parameterUserId)