开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜