On Aug 14, 2011, at 3:41 PM, cd34 wrote:

> 
> In the code, what I'm trying to accomplish is query against AuthUser,
> but, have ExtendedProfile's fields available to that query. It seemed
> like back_populate should do that, but, it says (correctly) that the
> AuthUser doesn't point to a mapper on ExtendedProfile.

OK back_populates has nothing to do with querying, it only involves the 
behavior of AuthUser and AuthUserProfile objects as they are assigned to 
reference each other in Python.   The docs at 
http://www.sqlalchemy.org/docs/orm/relationships.html#linking-relationships-with-backref
 should be pretty in-depth on this.

Reading some more here I think you're confusing it with "backref", which is 
more commonly used as it generates a relationship() in the other direction.   
back_populates associates two existing relationships with each other.

> 
> In this code sample, what I would like to do is query AuthUser, but,
> receive the ExtendedProfile class declarations.

Well those are two different classes, so first you'd need to assign a 
relationship() to AuthUser that references ExtendedProfile.  If you're looking 
for "backref" to do this via ExtendedProfile that's:

class ExtendedProfile(...):
    user = relationship("AuthUser", backref="profile")

this assigns a relationship() to ExtendedProfile and AuthUser.

Query then joins via the relationship():

session.query(AuthUser).join(AuthUser.profile).filter(ExtendedProfile.email=='foo')

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