GQL:多值属性上的不等于过滤器
对 GAE 的数据存储进行了一些修改,我发现我无法想出在多值属性上使用不等式过滤器“!=”过滤掉结果的正确方法:
class Entry(db.Model):
...
tags = db.StringListProperty()
e1 = Entry()
e2 = Entry()
e1.tags = ['tag1', 'tag2', 'tag3']
e2.tags = ['tag1', 'tag3', 'tag4']
# I want to exclude all the results containing 'tag2'
db.GqlQuery("""SELECT * FROM Entry
WHERE tags != 'tag2' """)
问题是此查询返回e1 和 e2 都有,但我只想要 e2。
我认为发生这种情况是因为不等式过滤器评估为 ANY(如果至少有一个值是 != 'tag2',则为 TRUE。有一种方法可以将过滤器应用于所有?(如果所有值都是 != 'tag2',则为 TRUE)?
我知道 GAE 的数据存储不是关系型的,但我想知道如何巧妙地解决/思考此类查询,
谢谢;)
Tinkering a little with GAE's datastore i've found that i can't think a proper way to filter out results using the inequality filter '!=' on a multivalued property:
class Entry(db.Model):
...
tags = db.StringListProperty()
e1 = Entry()
e2 = Entry()
e1.tags = ['tag1', 'tag2', 'tag3']
e2.tags = ['tag1', 'tag3', 'tag4']
# I want to exclude all the results containing 'tag2'
db.GqlQuery("""SELECT * FROM Entry
WHERE tags != 'tag2' """)
The problem is that this query returns both e1 and e2 but i want only e2.
I think that this happens because the inequality filter evaluates as ANY (TRUE if at least one value is != 'tag2'. There's a way to apply the filter to ALL? (TRUE if all the values are != 'tag2')?
I know that GAE's Datastore is not relational but i'd like to know how to cleverly solve/think this kind of queries.
Thanks ;)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经考虑了很多,但我认为没有一个好的方法可以做到这一点(如果我错了,请纠正我)。我的不聪明的解决方案是不使用 StringListProperty 并级联一堆过滤器:
我不会开始描述此解决方案的明显问题,但至少它可以满足您的要求。
I've thought about this a bunch and I don't think there is a good way to do it (please correct me if I'm wrong). My non-clever solution is to not use StringListProperty and to cascade a bunch of filters:
I'm not going to begin to describe the obvious problems with this solution, but at least it does what you want.