使用 GQL 按 ListProperty 的计数进行排序
如果我有一个 db.Model 对象,例如:
class Foo(db.Model):
title = db.StringProperty()
bars = db.ListProperty(db.Key)
并且我想查询数据存储中的所有 Foo 实体,并按具有最多条形的 Foo 对象对设置进行排序,我将如何编写 GQL?
我希望得到像这样简单的事情:
fooQuery = db.GqlQuery("SELECT * FROM Foo ORDER BY len(bars) DESC"
但这不起作用......
If I have an db.Model object such as:
class Foo(db.Model):
title = db.StringProperty()
bars = db.ListProperty(db.Key)
and I wanted to query the datastore for all of the Foo entities and sort that set by the Foo objects that have the most bars, how would I write the GQL?
I was hoping for something as simple as:
fooQuery = db.GqlQuery("SELECT * FROM Foo ORDER BY len(bars) DESC"
but that doesn't work...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要执行类似的操作,则必须包含另一个 IntegerProperty 来存储长度,并自行保持同步。 GQL 不支持该查询。
If you need to do something like that, you'll have to include another IntegerProperty to store the length, and keep it in sync yourself. GQL does not support that query.