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?
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...
Make sure you also define the index for this specific query and upload the index config file