entc/gen: skip selecting group-by fields if they already selected

This commit is contained in:
Ariel Mashraki
2021-04-19 16:17:57 +03:00
committed by Ariel Mashraki
parent 5421d6c628
commit 497fca4c96
82 changed files with 167 additions and 162 deletions

View File

@@ -679,14 +679,14 @@ func (ugb *UserGroupBy) sqlScan(ctx context.Context, v interface{}) error {
}
func (ugb *UserGroupBy) sqlQuery() *sql.Selector {
selector := ugb.sql
selector := ugb.sql.Select()
aggregation := make([]string, 0, len(ugb.fns))
for _, fn := range ugb.fns {
aggregation = append(aggregation, fn(selector))
}
// If no columns were selected in a custom aggregation function, the default
// selection is the fields used for "group-by", and the aggregation functions.
if len(selector.Columns()) == 0 {
if len(selector.SelectedColumns()) == 0 {
columns := make([]string, 0, len(ugb.fields)+len(ugb.fns))
for _, f := range ugb.fields {
columns = append(columns, selector.C(f))