使用排序顺序会破坏 Google App Engine 查询
我的应用程序引擎查询遇到问题。当我运行没有排序顺序的查询时,一切正常:
q = models.Contact.all();
q.filter("location = ", x);
if(cur_search_cursor != None):
q.with_cursor(cur_search_cursor);
results = q.fetch(limit = max_fetch)
cursor = q.cursor();
上面的查询正确返回值。但是,如果我只是将排序顺序添加到第一行,则根本不会返回任何内容:
q = models.Contact.all().order('name');
q.filter("location = ", x);
if(cur_search_cursor != None):
q.with_cursor(cur_search_cursor);
results = q.fetch(limit = max_fetch)
cursor = q.cursor();
不会引发异常,但也不会返回任何实体。我的代码中有错误吗?或者我是否必须在 index.yaml 文件中执行一些特殊操作才能使其正常工作?
我正在关闭 sqlite 的 dev_server 上尝试此操作。我还没有尝试在实际的 GAE 上测试它。
I'm having a problem with my app-engine queries. When I run my query without sort order, everything works just fine:
q = models.Contact.all();
q.filter("location = ", x);
if(cur_search_cursor != None):
q.with_cursor(cur_search_cursor);
results = q.fetch(limit = max_fetch)
cursor = q.cursor();
The above query properly returns values. However, if I simply add a sort order to the first line, nothing is returned at all:
q = models.Contact.all().order('name');
q.filter("location = ", x);
if(cur_search_cursor != None):
q.with_cursor(cur_search_cursor);
results = q.fetch(limit = max_fetch)
cursor = q.cursor();
No exception is raised, but no entities are returned either. Is there a bug in my code? Or do I have to do something special in my index.yaml file to get this to work?
I'm trying this on the dev_server with sqlite turned off. I haven't tried testing it on the actual GAE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了...“名称”字段是一个 TextProperty。根据文档, TextProperty 不可订购:
http://code.google.com/appengine/docs/python/datastore /typesandpropertyclasses.html
这浪费了三个小时。
Figured it out... the 'name' field is a TextProperty. A TextProperty is not orderable, as per the documentation:
http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html
That was a waste of three hours.