Fix the last bits of problems with auto inc pkey

This commit is contained in:
Aaron L 2016-08-13 16:32:32 -07:00
parent 944303f2f5
commit 8a7a9a35e8

View file

@ -55,18 +55,13 @@ func (o *{{$tableNameSingular}}) Insert(exec boil.Executor, whitelist ... string
return o.doAfterCreateHooks() return o.doAfterCreateHooks()
} }
lastId, err := result.lastInsertId() lastID, err := result.LastInsertId()
if err != nil || lastId == 0 { if err != nil || lastID == 0 || len({{$varNameSingular}}AutoIncPrimaryKeys) != 1 {
return ErrSyncFail return ErrSyncFail
} }
if len({{$varNameSingular}}AutoIncPrimaryKeys) != 1 { sel := fmt.Sprintf(`SELECT %s FROM {{.Table.Name}} WHERE %s`, strings.Join(returnColumns, `","`), strmangle.WhereClause(1, {{$varNameSingular}}AutoIncPrimaryKeys))
return ErrSyncFail err = exec.QueryRow(sel, lastID).Scan(boil.GetStructPointers(o, returnColumns...))
}
pkey := {{$varNameSingular}}AutoIncPrimaryKeys[0]
sel := fmt.Sprintf(`SELECT %s FROM {{.Table.Name}} WHERE %s`, strings.Join(returnColumns, `","`), strmangle.WhereClause(1, pkey))
err := exec.QueryRow(sel, lastId).Scan(boil.GetStructPointers(o, returnColumns...))
if err != nil { if err != nil {
return errors.Wrap(err, "{{.PkgName}}: unable to populate default values for {{.Table.Name}}") return errors.Wrap(err, "{{.PkgName}}: unable to populate default values for {{.Table.Name}}")
} }