如何在 Python Peewee ORM 的二阶 ForeignKeyField 中使用 where select?

How to do select with where on second order ForeignKeyField in Python Peewee ORM?

我正在使用(很棒的)Peewee ORM 来满足我的数据库需求,我现在构建了一个查询,如下所示:

OauthCI.select().where(OauthCI.oauth.user.id == 2)

所以 OauthCI 有一个名为 oauth 的 ForeignKeyField,它指向一个 table,后者又有一个名为 user 的 ForeignKeyField。不幸的是,这给了我一个错误提示:AttributeError: 'ForeignKeyField' object has no attribute 'user'.

有人知道我如何 select OauthCIoauthuser 以及 id 为 2 的所有记录吗?欢迎所有提示!

您的直觉很好,但不幸的是,peewee 目前无法正常工作。以下是您的做法:

OauthCI.select().join(Oauth).join(User).where(User.id == 2)