File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -505,7 +505,13 @@ class Timesheet(SQLModel, table=True):
505
505
# invoice: "Invoice" = Relationship(back_populates="timesheet")
506
506
# period: str
507
507
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
+ )
509
515
510
516
rendered : bool = Field (
511
517
default = False ,
@@ -572,7 +578,10 @@ class Invoice(SQLModel, table=True):
572
578
# Invoice 1:n Timesheet
573
579
timesheets : List [Timesheet ] = Relationship (
574
580
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
+ },
576
585
)
577
586
578
587
# status -- corresponds to InvoiceStatus enum above
You can’t perform that action at this time.
0 commit comments