Fix MySQL return query optimization.

- Before, this could erroneously detect that it could do without the
  return query because it thought all we wanted was the id. Now with
  this fix it should properly discard the query when all we want is id.
This commit is contained in:
Aaron L 2016-09-15 22:28:23 -07:00
parent bac82b6f0e
commit b0b0ff87c6
2 changed files with 6 additions and 4 deletions

View file

@ -104,7 +104,8 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string
if lastID != 0 {
{{- $colName := index .Table.PKey.Columns 0 -}}
{{- $col := .Table.GetColumn $colName -}}
o.{{$colName | singular | titleCase}} = {{$col.Type}}(lastID)
{{- $colTitled := $colName | singular | titleCase}}
o.{{$colTitled}} = {{$col.Type}}(lastID)
identifierCols = []interface{}{lastID}
} else {
identifierCols = []interface{}{
@ -114,7 +115,7 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string
}
}
if lastID != 0 && len(cache.retMapping) == 1 {
if lastID == 0 || len(cache.retMapping) != 1 || cache.retMapping[0] == {{$varNameSingular}}Mapping["{{$colTitled}}"] {
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
fmt.Fprintln(boil.DebugWriter, identifierCols...)

View file

@ -145,7 +145,8 @@ func (o *{{$tableNameSingular}}) Upsert(exec boil.Executor, {{if ne .DriverName
if lastID != 0 {
{{- $colName := index .Table.PKey.Columns 0 -}}
{{- $col := .Table.GetColumn $colName -}}
o.{{$colName | singular | titleCase}} = {{$col.Type}}(lastID)
{{- $colTitled := $colName | singular | titleCase}}
o.{{$colTitled}} = {{$col.Type}}(lastID)
identifierCols = []interface{}{lastID}
} else {
identifierCols = []interface{}{
@ -155,7 +156,7 @@ func (o *{{$tableNameSingular}}) Upsert(exec boil.Executor, {{if ne .DriverName
}
}
if lastID != 0 && len(cache.retMapping) == 1 {
if lastID == 0 || len(cache.retMapping) != 1 || cache.retMapping[0] == {{$varNameSingular}}Mapping["{{$colTitled}}"] {
if boil.DebugMode {
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
fmt.Fprintln(boil.DebugWriter, identifierCols...)