Ensure created_at isn't updated when unnecessary
- When we build the update whitelist (when the user doesn't provide one) we simply say that the whitelist is all columns except pkeys. The reason we do this is because sqlboiler doesn't support dirty tracking and if you want to update just a few fields, it's easier to just explicitly pass a whitelist when you update. However, in the case of created_at - it's a field that's usually managed by us and so we should not be updating it unless a user explicitly requests it via the whitelist. So if the whitelist is empty we prune that column now if it exists from the auto-created whitelist. - The user also reported that upsert has the same fate, but the logic is somewhat different there. It expects that there's a value for created_at or it assumes that one needs to be created. There's no more magic we can do around this one unfortunately. Upsert is a mythical beast that doesn't play as nicely with our model, so users will just have to be more careful. - Fix #106
This commit is contained in:
parent
8aa4e2148c
commit
a5cb765403
1 changed files with 5 additions and 0 deletions
|
@ -49,6 +49,11 @@ func (o *{{$tableNameSingular}}) Update(exec boil.Executor, whitelist ... string
|
|||
|
||||
if !cached {
|
||||
wl := strmangle.UpdateColumnSet({{$varNameSingular}}Columns, {{$varNameSingular}}PrimaryKeyColumns, whitelist)
|
||||
{{- if not .NoAutoTimestamps}}
|
||||
if len(whitelist) == 0 {
|
||||
wl = strmangle.SetComplement(wl, []string{"created_at"})
|
||||
}
|
||||
{{end -}}
|
||||
if len(wl) == 0 {
|
||||
return errors.New("{{.PkgName}}: unable to update {{.Table.Name}}, could not build whitelist")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue