diff --git a/backend/models.py b/backend/models.py index aa8a472..c2583f9 100644 --- a/backend/models.py +++ b/backend/models.py @@ -83,20 +83,13 @@ class Product(Base): shopping_events = relationship("ShoppingEvent", secondary=shopping_event_products, back_populates="products") # Self-referential many-to-many relationship for related products + # We'll use a simpler approach without back_populates to avoid circular references related_products = relationship( "Product", secondary=related_products, - primaryjoin=id == related_products.c.product_id, - secondaryjoin=id == related_products.c.related_product_id, - back_populates="related_to_products" - ) - - related_to_products = relationship( - "Product", - secondary=related_products, - primaryjoin=id == related_products.c.related_product_id, - secondaryjoin=id == related_products.c.product_id, - back_populates="related_products" + primaryjoin="Product.id == related_products.c.product_id", + secondaryjoin="Product.id == related_products.c.related_product_id", + viewonly=True ) class Shop(Base): diff --git a/backend/schemas.py b/backend/schemas.py index f8efc32..7f2609e 100644 --- a/backend/schemas.py +++ b/backend/schemas.py @@ -173,6 +173,7 @@ class ShopStats(BaseModel): # Update forward references BrandInShop.model_rebuild() +ProductWithRelated.model_rebuild() # Related Products schemas class RelatedProductBase(BaseModel):