entc/gen: support count with field selection

Fixed https://github.com/ent/ent/issues/2036
This commit is contained in:
Ariel Mashraki
2021-10-17 18:48:17 +03:00
committed by Ariel Mashraki
parent 732b2a7d6e
commit 3e6c40886d
92 changed files with 406 additions and 2 deletions

View File

@@ -91,6 +91,11 @@ func ({{ $receiver }} *{{ $builder }}) sqlCount(ctx context.Context) (int, error
{{- xtemplate $tmpl $ }}
{{- end }}
{{- end }}
_spec.Node.Columns = {{ $receiver }}.fields
if len({{ $receiver }}.fields) > 0 {
{{- /* In case of field selection, configure query to unique only if was explicitly set to true. */}}
_spec.Unique = {{ $receiver }}.unique != nil && *{{ $receiver }}.unique
}
return sqlgraph.CountNodes(ctx, {{ $receiver }}.driver, _spec)
}