remove card-group from join table on group remove

This commit is contained in:
Roland Osborne 2022-02-04 20:18:44 -08:00
parent 8e903dc1c1
commit d53399e306
2 changed files with 6 additions and 3 deletions

View File

@ -29,6 +29,9 @@ func RemoveGroup(w http.ResponseWriter, r *http.Request) {
}
err = store.DB.Transaction(func(tx *gorm.DB) error {
if res := tx.Model(slot.Group).Association("Cards").Clear(); res != nil {
return res
}
if res := tx.Delete(&slot.Group.GroupData).Error; res != nil {
return res
}

View File

@ -15,15 +15,15 @@ func TestUpdateContact(t *testing.T) {
var cards []Card
var detail int64
var profile int64
var cardProfile *CardProfile
var cardDetail *CardDetail
var cardProfile *CardProfile
// setup testing group
set, err = AddTestGroup("addaccount")
set, err = AddTestGroup("updatecontact")
assert.NoError(t, err)
// setup testing group
_, err = AddTestGroup("addaccount")
_, err = AddTestGroup("updatecontact")
assert.Error(t, err)
rev = GetTestRevision(set.B.Revisions)