Coverage for polar/models/checkout_link_product.py: 90%
19 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 17:15 +0000
1from typing import TYPE_CHECKING 1ab
2from uuid import UUID 1ab
4from sqlalchemy import ForeignKey, Integer, UniqueConstraint, Uuid 1ab
5from sqlalchemy.orm import Mapped, declared_attr, mapped_column, relationship 1ab
7from polar.kit.db.models import RecordModel 1ab
9if TYPE_CHECKING: 9 ↛ 10line 9 didn't jump to line 10 because the condition on line 9 was never true1ab
10 from polar.models import CheckoutLink, Product
13class CheckoutLinkProduct(RecordModel): 1ab
14 __tablename__ = "checkout_link_products" 1ab
15 __table_args__ = ( 1ab
16 UniqueConstraint("checkout_link_id", "product_id"),
17 UniqueConstraint("checkout_link_id", "order"),
18 )
20 checkout_link_id: Mapped[UUID] = mapped_column( 1ab
21 Uuid, ForeignKey("checkout_links.id", ondelete="cascade")
22 )
23 product_id: Mapped[UUID] = mapped_column( 1ab
24 Uuid, ForeignKey("products.id", ondelete="cascade")
25 )
26 order: Mapped[int] = mapped_column(Integer, nullable=False) 1ab
28 @declared_attr 1ab
29 def checkout_link(cls) -> Mapped["CheckoutLink"]: 1ab
30 return relationship("CheckoutLink", back_populates="checkout_link_products") 1ab
32 @declared_attr 1ab
33 def product(cls) -> Mapped["Product"]: 1ab
34 # This is an association table, so eager loading makes sense
35 return relationship("Product", lazy="joined") 1ab