Add cascading delete to Gift and Guest relationships
Updated the `ondelete="CASCADE"` behavior for foreign key constraints in Alembic migrations and added cascading rules to related models in SQLAlchemy. These changes ensure proper cleanup of dependent records when a parent record is deleted.
This commit is contained in:
@@ -68,10 +68,10 @@ class GiftItem(Base, UUIDMixin, TimestampMixin):
|
||||
category = relationship("GiftCategory", back_populates="gifts")
|
||||
reserved_by = relationship("Guest",
|
||||
secondary="guest_gifts",
|
||||
back_populates="gifts")
|
||||
back_populates="gifts", cascade='all')
|
||||
purchase_history = relationship("GiftPurchase",
|
||||
back_populates="gift_item",
|
||||
order_by="desc(GiftPurchase.purchased_at)")
|
||||
order_by="desc(GiftPurchase.purchased_at)", cascade='all, delete-orphan')
|
||||
|
||||
def __repr__(self):
|
||||
return f"<GiftItem {self.name} ({self.status.value})>"
|
||||
|
||||
Reference in New Issue
Block a user