From cba9f19ba50c60576a5961e89c24caefca52d740 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Sun, 3 Sep 2023 23:39:05 +0530 Subject: deleting addresses upon customer deletion --- customer/hooks.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'customer/hooks.go') diff --git a/customer/hooks.go b/customer/hooks.go index ac246f3..bef3308 100644 --- a/customer/hooks.go +++ b/customer/hooks.go @@ -39,5 +39,19 @@ func (c *Customer) BeforeDelete(tx *gorm.DB) error { return errors.ErrNoWhereCondition } + var err error + + // delete billing address + err = db.Where("customer_id = ?", c.ID).Delete(&CustomerBillingAddress{}).Error + if err != nil { + return err + } + + // delete shipping addresses + err = db.Where("customer_id = ?", c.ID).Delete(&CustomerShippingAddress{}).Error + if err != nil { + return err + } + return nil } -- cgit v1.2.3