drs7798 2012-07-25 20:37
浏览 12
已采纳

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

This question as already been answered for Python: How to get all records from GAE datastore with particular parent?

How do I do it in Go? I would like to do something like:

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)

...but this fails miserably with the following error:

datastore: query has no more results

When I try filtering by other properties, including those hard coded into the filter and those passed through the URL, the query runs properly and populates t with the proper properties. With what humiliating simplicity can my problem be fixed?

  • 写回答

2条回答 默认 最新

  • doushouj966020 2013-01-07 07:41
    关注

    What's tripping you up here is that querying by parent does not use Filter(). Instead, you use an ancestor constraint:

    q := datastore.NewQuery("TagRecord").
        Ancestor(k).
        Order("-CreatedAt").
        Limit(1)
    
    // etc...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)