diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-10-11 17:53:59 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.com> | 2025-10-11 17:53:59 +0530 |
commit | a8ce35aa10c0b61458aaee8820f8c937708f1133 (patch) | |
tree | c12a3b2aecd82729d1777299a563c46ab8ba61c6 | |
parent | 37fec5e9e7ef24c4f682bf5103b9d0bd6769ce8b (diff) |
properly deleting shipping addresses on customer editv0.14.0
-rw-r--r-- | customer/customer.go | 2 | ||||
-rw-r--r-- | customer/service.go | 1 | ||||
-rw-r--r-- | main.go | 2 |
3 files changed, 3 insertions, 2 deletions
diff --git a/customer/customer.go b/customer/customer.go index 6e7d2e5..c1290bf 100644 --- a/customer/customer.go +++ b/customer/customer.go @@ -54,5 +54,5 @@ type Customer struct { Email string Website string BillingAddress CustomerBillingAddress - ShippingAddresses []CustomerShippingAddress + ShippingAddresses []CustomerShippingAddress `gorm:"index;constraint:OnDelete:CASCADE;"` } diff --git a/customer/service.go b/customer/service.go index 77b4dfa..8cd2bde 100644 --- a/customer/service.go +++ b/customer/service.go @@ -53,6 +53,7 @@ func getCustomers(customers *[]Customer, userId uint) error { } func (c *Customer) upsert() error { + db.Model(&c).Association("ShippingAddresses").Replace(c.ShippingAddresses) res := db.Session(&gorm.Session{FullSaveAssociations: true}).Save(&c) // TODO: handle potential errors return res.Error @@ -38,7 +38,7 @@ import ( "log" ) -const OPENBILLS_VERSION = "v0.13.2" +const OPENBILLS_VERSION = "v0.14.0" func init() { if !viper.GetBool("debug_mode") { |