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?
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())
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With