Search code examples
google-app-enginegoogle-cloud-datastorebigtable

About the relationship in two entities


I'm thinking to create a property which store the key or the ID of the other entity as a reference to the entity.
I want to know two things.
1. Which data should the property store, the key or the ID?
2. What should the type of the property be? maybe StringProperty?


Solution

  • The Datastore has a special property type for this: ReferenceProperty. There are two ways to use it.

    One:

    someothermodel = db.ReferenceProperty()
    

    Two:

    someotherspecificmodel = db.ReferenceProperty(SomeModel)
    

    In example 2, only models with the type of SomeModel can be assigned, in example one, any model can be assigned.

    The value type of ReferenceProperty is db.Key.