Link new objects from the parent
Since SQLAlchemy 2.0, only the parent's end cascades a new object into the session'
This commit is contained in:
parent
87aaebe475
commit
ee5a372b2b
1 changed files with 21 additions and 6 deletions
|
|
@ -13,7 +13,11 @@ def make_address(city):
|
|||
|
||||
def func(**kwargs):
|
||||
"""Create an `Address` object in the `city`."""
|
||||
return factories.AddressFactory.build(city=city, **kwargs)
|
||||
address = factories.AddressFactory.build(**kwargs)
|
||||
|
||||
city.addresses.append(address)
|
||||
|
||||
return address
|
||||
|
||||
return func
|
||||
|
||||
|
|
@ -58,7 +62,11 @@ def make_restaurant(make_address):
|
|||
if address is None:
|
||||
address = make_address()
|
||||
|
||||
return factories.RestaurantFactory.build(address=address, **kwargs)
|
||||
restaurant = factories.RestaurantFactory.build(**kwargs)
|
||||
|
||||
address.restaurants.append(restaurant)
|
||||
|
||||
return restaurant
|
||||
|
||||
return func
|
||||
|
||||
|
|
@ -93,15 +101,18 @@ def make_order(make_address, make_courier, make_customer, make_restaurant):
|
|||
if courier is None:
|
||||
courier = make_courier()
|
||||
|
||||
return factory_cls.build(
|
||||
order = factory_cls.build(
|
||||
customer=make_customer(), # assume a unique `Customer` per order
|
||||
restaurant=restaurant,
|
||||
courier=courier,
|
||||
pickup_address=restaurant.address, # no `Address` history
|
||||
delivery_address=make_address(), # unique `Customer` => new `Address`
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
restaurant.orders.append(order)
|
||||
|
||||
return order
|
||||
|
||||
return func
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue