Skip to content

Commit 351c2a7

Browse files
committed
Merge branch 'main' into dev
2 parents 0e5d665 + dc2acf5 commit 351c2a7

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Diff for: tuttle/model.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,13 @@ class Timesheet(SQLModel, table=True):
505505
# invoice: "Invoice" = Relationship(back_populates="timesheet")
506506
# period: str
507507
comment: Optional[str] = Field(description="A comment on the timesheet.")
508-
items: List[TimeTrackingItem] = Relationship(back_populates="timesheet")
508+
items: List[TimeTrackingItem] = Relationship(
509+
back_populates="timesheet",
510+
sa_relationship_kwargs={
511+
"lazy": "subquery",
512+
"cascade": "all, delete", # delete all items when deleting a timesheet
513+
},
514+
)
509515

510516
rendered: bool = Field(
511517
default=False,
@@ -572,7 +578,10 @@ class Invoice(SQLModel, table=True):
572578
# Invoice 1:n Timesheet
573579
timesheets: List[Timesheet] = Relationship(
574580
back_populates="invoice",
575-
sa_relationship_kwargs={"lazy": "subquery"},
581+
sa_relationship_kwargs={
582+
"lazy": "subquery",
583+
"cascade": "all, delete", # delete all timesheets when invoice is deleted
584+
},
576585
)
577586

578587
# status -- corresponds to InvoiceStatus enum above
@@ -586,7 +595,10 @@ class Invoice(SQLModel, table=True):
586595
# invoice items
587596
items: List["InvoiceItem"] = Relationship(
588597
back_populates="invoice",
589-
sa_relationship_kwargs={"lazy": "subquery"},
598+
sa_relationship_kwargs={
599+
"lazy": "subquery",
600+
"cascade": "all, delete", # delete all invoice items when invoice is deleted
601+
},
590602
)
591603
rendered: bool = Field(
592604
default=False,

0 commit comments

Comments
 (0)