0

I made entities in parent-child relationship:

# Create Employee entity
employee = Employee()
employee.put()

# Set Employee as Address entity's parent directly...
address = Address(parent=employee)

# ...or using its key
e_key = employee.key()
address = Address(parent=e_key)

# Save Address entity to datastore
address.put()

Then, suppose that we only know the address entity and want to get the parent (employee). we can get address' parent:

address.key().parent()

However, I do not know how to get the employee's child when I know employee only. I found that Key.from_path(...) method was for getting Key from parent-child relationship, but I do not know how to deal with.

youminkim
  • 68
  • 5
  • Currently I think it is not possible to query children from parent. – specialscope May 17 '12 at 09:31
  • I do see Python in your question, still pasting this link to something similar in Java, if you could implement something similar: http://stackoverflow.com/questions/528650/google-app-engine-query-not-filter-for-children-of-an-entity – mhan May 17 '12 at 10:41

1 Answers1

1

You can query for (direct or indirect) children using the .ancestor() query filter, like this:

  addresses = Address.all().ancestor(emp).fetch()
systempuntoout
  • 71,966
  • 47
  • 171
  • 241
Nick Johnson
  • 100,655
  • 16
  • 128
  • 198