parent relationships

3 views
Skip to first unread message

Martin Webb

unread,
Sep 21, 2010, 3:52:49 AM9/21/10
to google-a...@googlegroups.com
Hi is it possible to add a entity of a model with a parent set to a key or another entity of the same model class. If so; does this make finding the siblings easier? If i load the parent or the sibling (child) is it easier to find the relating party(s).


 

Regards

 

 

Martin Webb



 

The information contained in this email is confidential and may contain proprietary information. It is meant solely for the intended recipient. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted in reliance on this, is prohibited and may be unlawful. No liability or responsibility is accepted if information or data is, for whatever reason corrupted or does not reach its intended recipient. No warranty is given that this email is free of viruses. The views expressed in this email are, unless otherwise stated, those of the author

 

 



Tim Hoffman

unread,
Sep 21, 2010, 4:34:23 AM9/21/10
to Google App Engine
Hi



On Sep 21, 3:52 pm, Martin Webb <spydre...@yahoo.co.uk> wrote:
> Hi is it possible to add a entity of a model with a parent set to a key or
> another entity of the same model class.
Parents can be any entity class.

> If so; does this make finding the
> siblings easier? If i load the parent or the sibling (child) is it easier to
> find the relating party(s).

Yes, if you only have one level of children below the parent. Children
within in children will mean you will get all children when doing a
straight ancestor query.

Remember you are also creating an entity group. So make sure you
don't create huge tree with a single parent ;-)

T

Martin Webb

unread,
Sep 21, 2010, 4:52:51 AM9/21/10
to google-a...@googlegroups.com
@tim
If i do need to store children with in children - and if i have childs that could run to say one level but perhaps 500-1000 entities is it best to use a different aproach?
Thinking about this i do need to store children with-in children so it sounds like i would have a problem getting the right level etc.
Am i correct.

 

Regards

 

 

Martin Webb

The information contained in this email is confidential and may contain proprietary information. It is meant solely for the intended recipient. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted in reliance on this, is prohibited and may be unlawful. No liability or responsibility is accepted if information or data is, for whatever reason corrupted or does not reach its intended recipient. No warranty is given that this email is free of viruses. The views expressed in this email are, unless otherwise stated, those of the author

 

 




From: Tim Hoffman <zute...@gmail.com>
To: Google App Engine <google-a...@googlegroups.com>
Sent: Tue, 21 September, 2010 9:34:23
Subject: [google-appengine] Re: parent relationships
--
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-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengine+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.


Tim Hoffman

unread,
Sep 21, 2010, 5:09:50 AM9/21/10
to Google App Engine
Hi

If you many levels deep you definately need to look at a different
approach. (unless you do want them all in the same entity group.)

I have implemented non entity group relation ship with the following
basic approach. Here is just a bit of the code to give you some
ideas.
The whole lot can be found at. (http://code.google.com/p/bfg-pages/
source/browse/trunk/pages/models.py#406 you will see zope'isms in the
real code)
I plan to add some transaction management around this based on some of
Nick Johnsons articles.

class ContentishMixin(db.Model):

parent_ = db.ReferenceProperty(collection_name='children_')
path_elements_ = db.StringListProperty(default=[])
display_order = db.IntegerProperty(default=5)

def setParent(self,obj):
self.parent_ = obj

class FolderishMixin(db.Model):

children_keys = db.ListProperty(db.Key,default=[])
children_names = db.StringListProperty(str,default=[])

def addContent(self,obj,name):

if name in self.contentNames():
raise DuplicateName('duplicate name %s'%name)

self.children_keys.append(obj.key())

self.children_names.append(name)
obj.setParent(self)
obj.path_elements_ = self.path_elements
obj.put()

self.put()

def __getitem__(self,name):

name = unquote(name))

if name in self.children_names:
idx = self.children_names.index(name)
result = self._get(self.children_keys[idx])
result.__parent__ = self
return result
else:
raise KeyError(name)

def __contains__(self,name):
if name in self.children_names:
return True
else:
return False

There is no transactions around any of this so if you have multiple
concurrent addContent calls to the same folder you will run into
trouble.

T


On Sep 21, 4:52 pm, Martin Webb <spydre...@yahoo.co.uk> wrote:
> @tim
>
> If i do need to store children with in children - and if i have childs that
> could run to say one level but perhaps 500-1000 entities is it best to use a
> different aproach?
> Thinking about this i do need to store children with-in children so it sounds
> like i would have a problem getting the right level etc.
> Am i correct.
>
> Regards
>
> Martin Webb
> The information contained in this email is confidential and may contain
> proprietary information. It is meant solely for the intended recipient. Access
> to this email by anyone else is unauthorised. If you are not the intended
> recipient, any disclosure, copying, distribution or any action taken or omitted
> in reliance on this, is prohibited and may be unlawful. No liability or
> responsibility is accepted if information or data is, for whatever reason
> corrupted or does not reach its intended recipient. No warranty is given that
> this email is free of viruses. The views expressed in this email are, unless
> otherwise stated, those of the author
>
> ________________________________
> From: Tim Hoffman <zutes...@gmail.com>
> google-appengi...@googlegroups.com.

Tim Hoffman

unread,
Sep 21, 2010, 5:14:02 AM9/21/10
to Google App Engine
If you want to entity groups and ancestor queries, I would define a
property of the children identifying depth from root.
The you can do a kindless ancestor query and filter by depth of parent
+ 1

T

On Sep 21, 4:52 pm, Martin Webb <spydre...@yahoo.co.uk> wrote:
> @tim
>
> If i do need to store children with in children - and if i have childs that
> could run to say one level but perhaps 500-1000 entities is it best to use a
> different aproach?
> Thinking about this i do need to store children with-in children so it sounds
> like i would have a problem getting the right level etc.
> Am i correct.
>
> Regards
>
> Martin Webb
> The information contained in this email is confidential and may contain
> proprietary information. It is meant solely for the intended recipient. Access
> to this email by anyone else is unauthorised. If you are not the intended
> recipient, any disclosure, copying, distribution or any action taken or omitted
> in reliance on this, is prohibited and may be unlawful. No liability or
> responsibility is accepted if information or data is, for whatever reason
> corrupted or does not reach its intended recipient. No warranty is given that
> this email is free of viruses. The views expressed in this email are, unless
> otherwise stated, those of the author
>
> ________________________________
> From: Tim Hoffman <zutes...@gmail.com>
> google-appengi...@googlegroups.com.

Martin Webb

unread,
Sep 21, 2010, 5:16:25 AM9/21/10
to google-a...@googlegroups.com
hi tim. Yes i have already implemented my own implementation. Tho i didnt use list properties as many users could be writting to the same entity and concurrency issues could begin. Tho i know that a fork-join-queue could be used to post the work from a queue. Thanks for the code i will take a look at this in more detail.

 

Regards

 

 

Martin Webb



 

The information contained in this email is confidential and may contain proprietary information. It is meant solely for the intended recipient. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted in reliance on this, is prohibited and may be unlawful. No liability or responsibility is accepted if information or data is, for whatever reason corrupted or does not reach its intended recipient. No warranty is given that this email is free of viruses. The views expressed in this email are, unless otherwise stated, those of the author

 

 




From: Tim Hoffman <zute...@gmail.com>

To: Google App Engine <google-a...@googlegroups.com>
Sent: Tue, 21 September, 2010 10:09:50
> google-appengine+unsub...@googlegroups.com.

> For more options, visit this group athttp://groups.google.com/group/google-appengine?hl=en.

--
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-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengine+unsub...@googlegroups.com.

Martin Webb

unread,
Sep 21, 2010, 5:21:20 AM9/21/10
to google-a...@googlegroups.com
Hi Tim. Just saw your last post. No i dont need something that complex. I dont need to sort them tho they could run into many thousands and beyond. I only need to load a say 10-100 at a time for display purposes. I did consider implementing as you have shown using the list property. But the issue of max 5000 entries plus the concurrency if multiple threads write made use a far less extragant model of just storing a domain key and then a key to a child as ref. i can then just fetch the childs by domain and then load them by key. It seems to work fine. Still pondering if it would be best to use a list property as you say ;-)

 

Regards

 

 

Martin Webb


T. 01233 660879
F. 01233 640949
M. 07798946071

 

The information contained in this email is confidential and may contain proprietary information. It is meant solely for the intended recipient. Access to this email by anyone else is unauthorised. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted in reliance on this, is prohibited and may be unlawful. No liability or responsibility is accepted if information or data is, for whatever reason corrupted or does not reach its intended recipient. No warranty is given that this email is free of viruses. The views expressed in this email are, unless otherwise stated, those of the author

 

 




From: Tim Hoffman <zute...@gmail.com>

To: Google App Engine <google-a...@googlegroups.com>
Sent: Tue, 21 September, 2010 10:14:02
> google-appengine+unsub...@googlegroups.com.

> For more options, visit this group athttp://groups.google.com/group/google-appengine?hl=en.

--
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-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengine+unsub...@googlegroups.com.

Tim Hoffman

unread,
Sep 21, 2010, 5:54:26 AM9/21/10
to Google App Engine
Just have a parent referenceproperty in the child and then use the
backref collection

In your case that will be the most efficient I think.

T

On Sep 21, 5:21 pm, Martin Webb <spydre...@yahoo.co.uk> wrote:
> Hi Tim. Just saw your last post. No i dont need something that complex. I dont
> need to sort them tho they could run into many thousands and beyond. I only need
> to load a say 10-100 at a time for display purposes. I did consider implementing
> as you have shown using the list property. But the issue of max 5000 entries
> plus the concurrency if multiple threads write made use a far less extragant
> model of just storing a domain key and then a key to a child as ref. i can then
> just fetch the childs by domain and then load them by key. It seems to work
> fine. Still pondering if it would be best to use a list property as you say ;-)
>
> Regards
>
> Martin Webb
>
> T. 01233 660879
> F. 01233 640949
> M. 07798946071
>
> The information contained in this email is confidential and may contain
> proprietary information. It is meant solely for the intended recipient. Access
> to this email by anyone else is unauthorised. If you are not the intended
> recipient, any disclosure, copying, distribution or any action taken or omitted
> in reliance on this, is prohibited and may be unlawful. No liability or
> responsibility is accepted if information or data is, for whatever reason
> corrupted or does not reach its intended recipient. No warranty is given that
> this email is free of viruses. The views expressed in this email are, unless
> otherwise stated, those of the author
>
> ________________________________
> > google-appengi...@googlegroups.com.
> > For more options, visit this group
> >athttp://groups.google.com/group/google-appengine?hl=en.
>
> --
> 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-a...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages