Reputation: 3434
For example, take the following snippet from the provided appengine-angular-gotodos :
func getAllTodos(c appengine.Context) ([]Todo, error) {
todos := []Todo{}
ks, err := datastore.NewQuery("Todo").Ancestor(defaultTodoList(c)).Order("Created").GetAll(c, &todos)
if err != nil {
return nil, err
}
for i := 0; i < len(todos); i++ {
todos[i].Id = ks[i].IntID()
}
return todos, nil
}
If you change the query to not include .Ancestor(defaultTodoList(c)).
the function fails to return any todo results.
Upvotes: 1
Views: 409
Reputation: 479
If an entity is saved with an ancestry, must you query it by that ancestor?
No you don't have to.
How do you query for Entities regardless of whether they are children, or root entities?
Reduced to as simple an example as possible from here:
//Assuming c is your appengine context
q = datastore.NewQuery("MyObject") // Can add filters and sorting here if desired.
for t := q.Run(c);; {
var x MyObject
key, err := t.Next(&x)
}
I also found this note here:
Note: Setting an ancestor filter allows for strongly consistent queries. Queries without an ancestor filter only return eventually consistent results.
This is important because I believe all datastores are HRD now. You can read more about high replication datastores.
Upvotes: 1
Reputation: 4178
defaultTodoList(c)
might not contain the parent Entity that the code expects it to contain. Try to verify its value somehow before using it, for example by storing it in a variable and then logging data out of it.
Upvotes: 0