Commit 0c9ea3fd authored by zauberstuhl's avatar zauberstuhl

Fix opt_in not update-able via gorm

You have to specify opt_in as extra update field
since gorm will not update if bool is false
see http://gorm.io/docs/update.html
parent 1c35276c
......@@ -142,13 +142,12 @@ func resultPage(w http.ResponseWriter, r *http.Request) {
return
}
}
err = repo.CreateOrUpdate()
if err != nil {
logger.Println(err)
render(w, "error.html", "Cannot insert/update the database record")
return
}
}
err := repo.CreateOrUpdate()
if err != nil {
logger.Println(err)
render(w, "error.html", "Cannot insert/update the database record")
return
}
render(w, "result.html", repo.Slug)
......
......@@ -62,8 +62,11 @@ func (repo *Repo) CreateOrUpdate() error {
return err
}
} else if err == nil {
repo.ID = oldRecord.ID
err = db.Update(repo).Error
// NOTE you have to specify opt_in as extra update field
// since gorm will not update if bool is false
// see http://gorm.io/docs/update.html
err = db.Model(repo).Where("id = ?", oldRecord.ID).
Update(repo).Update("opt_in", repo.OptIn).Error
if err != nil {
return err
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment