سؤال

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