Coverage for polar/models/discount_product.py: 89%
17 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 12:42 +0000
1from typing import TYPE_CHECKING
2from uuid import UUID
4from sqlalchemy import ForeignKey, Uuid
5from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship
7from polar.kit.db.models import RecordModel
9if TYPE_CHECKING: 9 ↛ 10line 9 didn't jump to line 10 because the condition on line 9 was never true
10 from polar.models import Discount, Product
13class DiscountProduct(RecordModel):
14 __tablename__ = "discount_products"
16 discount_id: Mapped[UUID] = mapped_column(
17 Uuid,
18 ForeignKey("discounts.id", ondelete="cascade"),
19 primary_key=True,
20 )
21 product_id: Mapped[UUID] = mapped_column(
22 Uuid,
23 ForeignKey("products.id", ondelete="cascade"),
24 primary_key=True,
25 )
27 @declared_attr
28 def discount(cls) -> Mapped["Discount"]:
29 return relationship(
30 "Discount", lazy="raise", back_populates="discount_products"
31 )
33 @declared_attr
34 def product(cls) -> Mapped["Product"]:
35 # This is an association table, so eager loading makes sense
36 return relationship("Product", lazy="joined")