I use the following structure:
class Tag (db.Expando):
label = StringProperty()
parent_ = SelfReferenceProperty(collection_name='children')
This is a simplified for illustration purposes, but it works well
enough for us because we just grab all Tag entities and build the tree
in memory with a single simple function. Of course, we will never be
more than 3-4 deep and always have less than 100 tags total.
On Jul 13, 5:17 am, Nick Johnson (Google) nick.john...@google.com
wrote:
Hi Peter,
On Sun, Jul 12, 2009 at 8:31 PM, Peter Cicmanpcic...@gmail.com wrote:
I had spend some time today with building tree structure using
datastore. I need a real tree, for real world, so there must be a
possibility to move node with all descendants. There must also be a
quick way to find all ancestors, children and descendants.
I'm not aware of any tree structure that fits both those requirements
- in fact, I'm fairly sure it's not possible.
There are two basic approaches to representing trees: Ones that
encompass the node's position in the entire tree, such as materialized
path and nested set notation, and ones that only encompass the node's
relationship to neighbouring nodes, such as adjacency lists. The
former permit easily querying all descendants, while the latter make
it easy to move entire branches. I don't think it's possible to have
both at once.
If moving a branch is less common than querying, and your trees are
relatively shallow (Say, less than 100 levels deep), I would recommend
using the materialized path approach: Have a ListProperty that lists
all the ancestors of the node.
-Nick Johnson
So, datastore keys can not be used for tree like this - because key
can not change, and i would like to prevent node copying/deletion,
because this must be always done on node and all its descendants which
may end up with tons of sql queries.
Design i made should fit for me, but maybe there is some common
solution for this problem... Anybody knows about some optimal
solution? (i can not use serialization)
Thanks a lot!
--
Nick Johnson, App Engine Developer Programs Engineer
Google Ireland Ltd. :: Registered in Dublin, Ireland, Registration
Number: 368047
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
Google App Engine group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~--~~~~--~~--~--~---