通过父实体过滤数据存储结果

时间:2012-07-25 20:37:26

标签: google-app-engine google-cloud-datastore go

这个问题已经为Python解答了: How to get all records from GAE datastore with particular parent?

我如何在Go中执行此操作?我想做点什么:

t := new(TagRecord)
k, err := datastore.DecodeKey(r.URL.Path[1:])
...
_, err = datastore.NewQuery("TagRecord").
  Filter("Parent =", k). 
  Order("-CreatedAt").
  Limit(1).
  Run(c).Next(t)

...但是由于以下错误而失败:

datastore: query has no more results

当我尝试使用其他属性进行过滤时,包括那些硬编码到过滤器中的属性以及通过URL传递的属性,查询会正常运行并使用适当的属性填充t。羞辱简单可以解决我的问题吗?

2 个答案:

答案 0 :(得分:2)

在这里绊倒的是父母查询不使用Filter()。相反,您使用ancestor constraint

q := datastore.NewQuery("TagRecord").
    Ancestor(k).
    Order("-CreatedAt").
    Limit(1)

// etc...

答案 1 :(得分:0)

确保您还定义了此特定查询的索引并上传了索引配置文件