--
You received this message because you are subscribed to the Google Groups "peewee-orm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to peewee-orm+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
OpponentUser = User.alias()
result = GameResult.select(GameResult, User, OpponentUser)\
.switch(GameResult).join(User, on=GameResult.user)\
.switch(GameResult).join(OpponentUser, JOIN.LEFT_OUTER,
on=(GameResult.opponent==OpponentUser.id))\
.where(GameResult.id==id).get()
For more options, visit https://groups.google.com/d/optout.
If you add an alias to the second join specifying which attribute to use, peewee will do the right thing:
Opponent = User.alias() query = (GameResult .select(GameResult, User, Opponent) .join(User, on=(GameResult.user == User.id)) .switch(GameResult) .join(Opponent, on=(GameResult.opponent == Opponent.id).alias('opponent')) .order_by(Game.id))
I think peewee has enough info here, though, to perhaps determine that the opponent field is what we want. I will look into a fix.