One-to-many relationship

Here is an example of one-to-many relationship:

  1. class Order(db.Entity):
  2. items = Set("OrderItem")
  3. class OrderItem(db.Entity):
  4. order = Required(Order)

In the example above the instance of OrderItem cannot exist without an order. If we want to allow an instance of OrderItem to exist without being assigned to an order, we can define the order attribute as Optional:

  1. class Order(db.Entity):
  2. items = Set("OrderItem")
  3. class OrderItem(db.Entity):
  4. order = Optional(Order)