querying relation does not give back related object in sqlalchemy
I have a very simple table(mapped as AuthToken class), consisting of a string ('token'), and a userid (foreign key to another table), with 'user' as relation ( = class User)
session.query(AuthToken.user).one开发者_运维问答() gives back the token, and the userid (as a tuple), but not the user object.
Does anybody know why?
thanks!
You should query mapped classes, not their attributes, if you want to receive objects.
token = Session.query(AuthToken).options(eagerload('user')).filter(...).one()
user = token.user
精彩评论