문제

I currently have two peewee models "User" and "Game". Every Game can have many users and they are related by a ForeignKeyField in User. I'm simply trying fetch all users with a certain game id but I haven't been able to figure out how. So far I've tried:

User.select().where(User.game.id == game_id)

and:

User.select().where(User.game_id == game_id)

I'm probably missing something really trivial here so any help will be greatly appreciated.

도움이 되었습니까?

해결책

You need to do a join:

User.select().join(Game).where(Game.id == game_id)

The code might differ from what you need, as I do not know how your models look in detail. Please check out the peewee documentation on joining.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top