One-to-many relationship
Here is an example of one-to-many relationship:
class Order(db.Entity):
items = Set("OrderItem")
class OrderItem(db.Entity):
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
:
class Order(db.Entity):
items = Set("OrderItem")
class OrderItem(db.Entity):
order = Optional(Order)