mirror of
https://github.com/ent/ent.git
synced 2026-05-01 07:00:57 +03:00
entc/gen: support count with field selection
Fixed https://github.com/ent/ent/issues/2036
This commit is contained in:
committed by
Ariel Mashraki
parent
732b2a7d6e
commit
3e6c40886d
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user