Coverage for polar/models/checkout_link_product.py: 90%
19 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, Integer, UniqueConstraint, 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 CheckoutLink, Product
13class CheckoutLinkProduct(RecordModel):
14 __tablename__ = "checkout_link_products"
15 __table_args__ = (
16 UniqueConstraint("checkout_link_id", "product_id"),
17 UniqueConstraint("checkout_link_id", "order"),
18 )
20 checkout_link_id: Mapped[UUID] = mapped_column(
21 Uuid, ForeignKey("checkout_links.id", ondelete="cascade")
22 )
23 product_id: Mapped[UUID] = mapped_column(
24 Uuid, ForeignKey("products.id", ondelete="cascade")
25 )
26 order: Mapped[int] = mapped_column(Integer, nullable=False)
28 @declared_attr
29 def checkout_link(cls) -> Mapped["CheckoutLink"]:
30 return relationship("CheckoutLink", back_populates="checkout_link_products")
32 @declared_attr
33 def product(cls) -> Mapped["Product"]:
34 # This is an association table, so eager loading makes sense
35 return relationship("Product", lazy="joined")