Great Grandpa Query (yet another ancestor question)

27 views
Skip to first unread message

gor

unread,
Jun 24, 2012, 11:17:50 PM6/24/12
to google-a...@googlegroups.com
Scenario 1:
If I have a Great Grandpa ancestor (let's name him A); And my key is from "child1"; is there a way to check that my great grandpa is A? (hope I can do that without needing to loop)

Or can I check, if child1's key is of the path "A->B->C".
A -> B -> C -> (child1, child2...)

Scenario 2:
From the above. Great Grandpa has another descendants from "G", and would like to retrieve "H"s children:

A-> B -> C -> (children of C)
...-> G -> H -> (children of H)

I like to retrieve "H"s children, thinking that Grandpa knows the path from A, G, to H... can I do that? (hope I can do this in a query, without looping)

If you have a Go1 example: that would be awesome... 

Thanks Google! and I love you!


timh

unread,
Jun 24, 2012, 11:49:12 PM6/24/12
to google-a...@googlegroups.com
Hi

Here is one approach you could use.

In each entity store a list of paths of each parent.  ie in second scenario

H has a list property called parent_paths it would have the following values ['/a/g','/a'] and its children would have ['/a','/a/g','/a/g/h'] etc

Then given any entity you can fetch all levels of descendants. So in your example  you just need to query for any entity
that has '/a/g/h'  in its parent_paths.  This doesn't allow you to restrict depth though.

Cheers

Tim

gor

unread,
Jun 25, 2012, 12:35:11 AM6/25/12
to google-a...@googlegroups.com
the parent_path property could work. thanks.

timh

unread,
Jun 25, 2012, 12:53:05 AM6/25/12
to google-a...@googlegroups.com
hi

If you store the depth of the path as an integer property of each child, you can then restrict you query by the depth below a parent as well.

Cheers

T

gor

unread,
Jun 25, 2012, 2:36:32 AM6/25/12
to google-a...@googlegroups.com
right. thanks for the ideas.
Reply all
Reply to author
Forward
0 new messages