使用 GQL 按 ListProperty 的计数进行排序

发布于 2024-09-25 22:20:36 字数 346 浏览 0 评论 0原文

如果我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你是年少的欢喜 2024-10-02 22:20:36

如果您需要执行类似的操作,则必须包含另一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文