Correct caching for upserts with no returns

- Previously it would return early, and therefore no caching was being
  performed since it would never write to the cache.
This commit is contained in:
Aaron L 2016-09-15 22:17:12 -07:00
parent 440e3a1343
commit bac82b6f0e

View file

@ -131,20 +131,17 @@ func (o *{{$tableNameSingular}}) Upsert(exec boil.Executor, {{if ne .DriverName
return errors.Wrap(err, "{{.PkgName}}: unable to upsert for {{.Table.Name}}")
}
var lastID int64
var identifierCols []interface{}
if len(cache.retMapping) == 0 {
{{if not .NoHooks -}}
return o.doAfterUpsertHooks(exec)
{{else -}}
return nil
{{end -}}
goto CacheNoHooks
}
lastID, err := result.LastInsertId()
lastID, err = result.LastInsertId()
if err != nil {
return ErrSyncFail
}
var identifierCols []interface{}
if lastID != 0 {
{{- $colName := index .Table.PKey.Columns 0 -}}
{{- $col := .Table.GetColumn $colName -}}
@ -180,6 +177,9 @@ func (o *{{$tableNameSingular}}) Upsert(exec boil.Executor, {{if ne .DriverName
}
{{- end}}
{{if .UseLastInsertID -}}
CacheNoHooks:
{{end -}}
if !cached {
{{$varNameSingular}}UpsertCacheMut.Lock()
{{$varNameSingular}}UpsertCache[key] = cache