Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between a parent and a reference property in Google App Engine?

From what I understand, the parent attribute of a db.Model (typically defined/passed in the constructor call) allows you to define hierarchies in your data models. As a result, this increases the size of the entity group. However, it's not very clear to me why we would want to do that. Is this strictly for ACID compliance? I would like to see scenarios where each is best suited or more appropriate.

like image 686
fuentesjr Avatar asked Oct 18 '08 21:10

fuentesjr


2 Answers

There are several differences:

  • All entities with the same ancestor are in the same entity group. Transactions can only affect entities inside a single entity group.
  • All writes to a single entity group are serialized, so throughput is limited.
  • The parent entity is set on creation and is fixed. References can be changed at any time.
  • With reference properties, you can only query for direct relationships, but with parent properties you can use the .ancestor() filter to find everything (directly or indirectly) descended from a given ancestor.
  • Each entity has only a single parent, but can have multiple reference properties.
like image 163
Nick Johnson Avatar answered Oct 05 '22 23:10

Nick Johnson


The only purpose of entity groups (defined by the parent attribute) is to enable transactions among different entities. If you don't need the transactions, don't use the entity group relationships.

I suggest you re-reading the Keys and Entity Groups section of the docs, it took me quite a few reads to grasp the idea.

Also watch these talks, among other things they discuss transactions and entity groups:

  • Building Scalable Web Applications with Google App Engine
  • Under the Covers of the Google App Engine Datastore
like image 29
Alexander Kojevnikov Avatar answered Oct 05 '22 22:10

Alexander Kojevnikov