使用排序顺序会导致Google App Engine查询失败

0 投票
1 回答
667 浏览
提问于 2025-04-16 09:09

我在使用应用引擎查询的时候遇到了一些问题。当我运行没有排序的查询时,一切都正常:

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。我还没有在实际的GAE上进行测试。

1 个回答

4

我搞明白了……'name'字段是一个文本属性。文本属性是不能排序的,这在文档里有说明:http://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.html

真是浪费了三个小时。

撰写回答