diff --git a/database.py b/database.py index a1ece93..6887650 100644 --- a/database.py +++ b/database.py @@ -297,6 +297,7 @@ class OrderItem(DeferredReflection, TableDeclarativeBase): product = relationship("Product") # The order in which this item is being purchased order_id = Column(Integer, ForeignKey("orders.order_id"), nullable=False) + order = relationship("Order") # Extra table parameters __tablename__ = "orderitems" diff --git a/worker.py b/worker.py index ef4926a..89fdddf 100644 --- a/worker.py +++ b/worker.py @@ -652,7 +652,7 @@ class Worker(threading.Thread): # Create {quantity} new OrderItems for i in range(0, cart[product][1]): order_item = db.OrderItem(product=cart[product][0], - order_id=order.order_id) + order=order) self.session.add(order_item) # Ensure the user has enough credit to make the purchase credit_required = self.__get_cart_value(cart) - self.user.credit