Add quantity column to GuestGifts table and update references
Introduced a `quantity` field to track the number of reserved gifts in the many-to-many GuestGifts table. Updated all related CRUD operations, models, and imports to reflect the added column. Replaced `guest_gifts` with `GuestGifts` for consistency in naming conventions.
This commit is contained in:
@@ -94,13 +94,14 @@ class CRUDGiftItem(CRUDBase[GiftItem, GiftItemCreate, GiftItemUpdate]):
|
||||
gift: GiftItem = self.get(db, gift_id)
|
||||
if gift and gift.quantity_received < gift.quantity_requested:
|
||||
# Add to the association table using the SQLAlchemy Core Table directly
|
||||
from app.models.guest import guest_gifts
|
||||
from app.models.guest import GuestGifts
|
||||
|
||||
stmt = guest_gifts.insert().values(
|
||||
stmt = GuestGifts.insert().values(
|
||||
gift_id=gift_id,
|
||||
guest_id=guest_id,
|
||||
reserved_at=datetime.now(timezone.utc),
|
||||
notes=notes
|
||||
notes=notes,
|
||||
quantity=quantity
|
||||
)
|
||||
db.execute(stmt)
|
||||
|
||||
@@ -336,12 +337,12 @@ class CRUDGiftPurchase(CRUDBase[GiftPurchase, GiftPurchaseCreate, GiftPurchaseUp
|
||||
for gift in guest.gifts:
|
||||
# Access the association data through the relationship metadata
|
||||
from sqlalchemy import select
|
||||
from app.models.guest import guest_gifts
|
||||
from app.models.guest import GuestGifts
|
||||
|
||||
# Get the reservation data
|
||||
stmt = select(guest_gifts).where(
|
||||
(guest_gifts.c.guest_id == guest_id) &
|
||||
(guest_gifts.c.gift_id == gift.id)
|
||||
stmt = select(GuestGifts).where(
|
||||
(GuestGifts.c.guest_id == guest_id) &
|
||||
(GuestGifts.c.gift_id == gift.id)
|
||||
)
|
||||
reservation = db.execute(stmt).first()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user