Fix insert and update whitelist generators

This commit is contained in:
Patrick O'brien 2016-08-04 13:55:25 +10:00
parent b8b44eba98
commit ed2c5e407d
2 changed files with 6 additions and 14 deletions

View file

@ -105,12 +105,13 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string
// - add all columns that have a default in the database but that are non-zero in the struct
// - the return columns are the result of (columns with default values - the previous set)
func (o *{{$tableNameSingular}}) generateInsertColumns(whitelist ...string) ([]string, []string) {
if len(whitelist) != 0 {
return whitelist, boil.SetComplement({{$varNameSingular}}ColumnsWithDefault, whitelist)
}
var wl []string
wl = append(wl, whitelist...)
if len(whitelist) == 0 {
wl = append(wl, {{$varNameSingular}}ColumnsWithoutDefault...)
}
wl = append(wl, {{$varNameSingular}}ColumnsWithoutDefault...)
wl = append(boil.NonZeroDefaultSet({{$varNameSingular}}ColumnsWithDefault, o), wl...)
wl = boil.SortByKeys({{$varNameSingular}}Columns, wl)

View file

@ -121,14 +121,5 @@ func (o *{{$tableNameSingular}}) generateUpdateColumns(whitelist ...string) []st
return whitelist
}
var wl []string
cols := {{$varNameSingular}}ColumnsWithoutDefault
cols = append(boil.NonZeroDefaultSet({{$varNameSingular}}ColumnsWithDefault, o), cols...)
// Subtract primary keys and autoincrement columns
cols = boil.SetComplement(cols, {{$varNameSingular}}PrimaryKeyColumns)
wl = make([]string, len(cols))
copy(wl, cols)
return wl
return boil.SetComplement({{$varNameSingular}}Columns, {{$varNameSingular}}PrimaryKeyColumns)
}