From cec2da512890e4e5fe893aaf2a223a501408370d Mon Sep 17 00:00:00 2001 From: Vivek Kekuda Date: Thu, 13 Oct 2022 20:46:37 +0530 Subject: [PATCH] Fix new records being added on completing a campaign (#2599) There were new records with name '[Deleted]' being added when a campaign was completed. This used to happen when the resource associated with a campaign (template, page, profile) was deleted before marking the campaign as completed. The save gorm call used to upsert these values and ended up adding rogue records. --- models/campaign.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/models/campaign.go b/models/campaign.go index a9e24382..debca6ab 100644 --- a/models/campaign.go +++ b/models/campaign.go @@ -661,7 +661,8 @@ func CompleteCampaign(id int64, uid int64) error { // Mark the campaign as complete c.CompletedDate = time.Now().UTC() c.Status = CampaignComplete - err = db.Where("id=? and user_id=?", id, uid).Save(&c).Error + err = db.Model(&Campaign{}).Where("id=? and user_id=?", id, uid). + Select([]string{"completed_date", "status"}).UpdateColumns(&c).Error if err != nil { log.Error(err) }