fix db errror

This commit is contained in:
lasse 2025-05-28 09:25:24 +02:00
parent 112ea41e88
commit 666ce5d4d4
2 changed files with 5 additions and 11 deletions

View File

@ -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):

View File

@ -173,6 +173,7 @@ class ShopStats(BaseModel):
# Update forward references
BrandInShop.model_rebuild()
ProductWithRelated.model_rebuild()
# Related Products schemas
class RelatedProductBase(BaseModel):