Google app引擎gql查询两个属性相同的字符串

Chi*_*ang 3 python google-app-engine

我有一个名为的数据模型Game.

Game模型中,我有两个属性player1,player2它们是名称.

我想找到一个播放器,game但我不知道如何构建查询,因为gql不支持OR子句,然后我不能使用select * from Game where player1 = 'tom' or player2 = 'tom'语句.

那么,我该如何解决这个问题呢?
我是否必须修改我的数据模型?

Dre*_*ars 6

使用当前的数据模型,您需要执行2个查询,一个用于player1,另一个用于player2,然后将结果合并到本地Python代码中.

需要更改架构的另一个选项是使用单个ListProperty替换两个字段,例如:

class Game(db.Model):
  players = db.ListProperty()

game1.players = ['tom', 'bob']
game2.players = ['joe', 'tom']

# this query will match all games where tom is one of the players
query = Game.all().filter('players =', 'tom')
Run Code Online (Sandbox Code Playgroud)

这是有效的,因为现在可以使用单个索引查询玩家.