Make Grid.gridify() use only pickup addresses
- ensure a `Restaurant` only has one unique `Order.pickup_address` - rework `Grid.gridify()` so that only pickup addresses are assigned into `Pixel`s - include database migrations to ensure the data adhere to these tighter constraints
This commit is contained in:
parent
0c1ff5338d
commit
1bfc7db916
11 changed files with 519 additions and 61 deletions
|
|
@ -79,12 +79,6 @@ class Order(meta.Base): # noqa:WPS214
|
|||
sa.ForeignKeyConstraint(
|
||||
['customer_id'], ['customers.id'], onupdate='RESTRICT', ondelete='RESTRICT',
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['restaurant_id'],
|
||||
['restaurants.id'],
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['courier_id'], ['couriers.id'], onupdate='RESTRICT', ondelete='RESTRICT',
|
||||
),
|
||||
|
|
@ -94,6 +88,14 @@ class Order(meta.Base): # noqa:WPS214
|
|||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
# This foreign key ensures that there is only
|
||||
# one `.pickup_address` per `.restaurant`
|
||||
['restaurant_id', 'pickup_address_id'],
|
||||
['restaurants.id', 'restaurants.address_id'],
|
||||
onupdate='RESTRICT',
|
||||
ondelete='RESTRICT',
|
||||
),
|
||||
sa.ForeignKeyConstraint(
|
||||
['delivery_address_id'],
|
||||
['addresses.id'],
|
||||
|
|
@ -302,7 +304,11 @@ class Order(meta.Base): # noqa:WPS214
|
|||
|
||||
# Relationships
|
||||
customer = orm.relationship('Customer', back_populates='orders')
|
||||
restaurant = orm.relationship('Restaurant', back_populates='orders')
|
||||
restaurant = orm.relationship(
|
||||
'Restaurant',
|
||||
back_populates='orders',
|
||||
primaryjoin='Restaurant.id == Order.restaurant_id',
|
||||
)
|
||||
courier = orm.relationship('Courier', back_populates='orders')
|
||||
pickup_address = orm.relationship(
|
||||
'Address',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue