Nigiri
Nigiri

Reputation: 3639

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?

Upvotes: 0

Views: 38

Answers (1)

Linuxios
Linuxios

Reputation: 35803

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.

Upvotes: 1

Related Questions