From cb081f4a17f8212e5f0dfd184373c410ea65b108 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Feb 2015 20:17:25 -0600 Subject: [PATCH] Can now add files to a previously created template that didn't have files to begin with Fixes #8 --- models/template.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/models/template.go b/models/template.go index d3d797b3..eca28f00 100644 --- a/models/template.go +++ b/models/template.go @@ -46,13 +46,13 @@ func GetTemplates(uid int64) ([]Template, error) { } for i, _ := range ts { err = db.Where("template_id=?", ts[i].Id).Find(&ts[i].Attachments).Error + if err == nil && len(ts[i].Attachments) == 0 { + ts[i].Attachments = make([]Attachment, 0) + } if err != nil && err != gorm.RecordNotFound { Logger.Println(err) return ts, err } - if err == gorm.RecordNotFound { - err = nil - } } return ts, err } @@ -70,8 +70,8 @@ func GetTemplate(id int64, uid int64) (Template, error) { Logger.Println(err) return t, err } - if err == gorm.RecordNotFound { - err = nil + if err == nil && len(t.Attachments) == 0 { + t.Attachments = make([]Attachment, 0) } return t, err }