entc/gen: fix update ids check bug in user-defined-ids

Summary: Pull Request resolved: https://github.com/facebookincubator/ent/pull/203

Reviewed By: alexsn

Differential Revision: D18725824

fbshipit-source-id: 888686bb5fa87649be89ec1926cbd7a3b6cf7932
This commit is contained in:
Ariel Mashraki
2019-11-27 06:11:04 -08:00
committed by Facebook Github Bot
parent ed3747ff82
commit 5fe9fcdc1b
13 changed files with 27 additions and 115 deletions

View File

@@ -75,14 +75,14 @@ func ({{ $receiver }} *{{ $builder }}) sqlSave(ctx context.Context) ({{ $ret }}
res sql.Result
updater = builder.Update({{ $.Package }}.Table)
)
{{- if $.ID.IsInt }}
updater = updater.Where(sql.InInts({{ $.Package }}.{{ $.ID.Constant }}, ids...))
{{- else }}
{{- if and (not $.ID.IsInt) $.ID.UserDefined }}
idface := make([]interface{}, len(ids))
for i := range ids {
idface[i] = ids[i]
}
updater = updater.Where(sql.In({{ $.Package }}.{{ $.ID.Constant }}, idface...))
{{- else }}
updater = updater.Where(sql.InInts({{ $.Package }}.{{ $.ID.Constant }}, ids...))
{{- end }}
{{- range $_, $f := $.Fields }}
{{- if or (not $f.Immutable) $f.UpdateDefault }}