Вопрос

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