Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppEngine - When to use a parent relationship?

I'm trying to understand when to use an entity "parent" on GAE. Is this only useful for querying (ie get all the Foo objects where the parent == someObj) or does the child have access to the parent entity much like a ReferenceProperty?

When is it better to use the parent vs ReferenceProperty?

like image 430
MattoTodd Avatar asked Aug 07 '11 23:08

MattoTodd


2 Answers

The only time you should use entity groups (which is what all entities with a common parent form) is for transactional safety. If you need to update multiple records in a transaction, they all need to have the same root entity. The reason you wouldn't just put all your entities under a single parent is because updates to an entity group are limited to roughly 1 per second. For more information, see this section of the documentation.

An entity can access its parent with this.parent, but there's nothing special about it - that's just syntactic sugar for db.get(this.key().parent()).

like image 76
Nick Johnson Avatar answered Oct 22 '22 16:10

Nick Johnson


Everything I read is against Parent entities for one reason, and that is when you modify anything in that tree, everything is locked.

When I first started working with parent entities, I wanted to treat them like the head of a hive or a database localized around that parent entry but apparently that isn't the way they are done. You probably want to just use ReferenceProperty because that will allow you access to the parent, and won't cause the locking to go on.

Of course, if you are wanting that kind of relationship locking, then maybe you do want it, but you weren't specific enough for me to gauge that.

like image 29
boatcoder Avatar answered Oct 22 '22 16:10

boatcoder