enable distinct in sqlQuery

This commit is contained in:
Lining Guan
2021-09-18 16:01:11 +08:00
parent 5f31091dcd
commit f42014f019
5 changed files with 12 additions and 1 deletions

View File

@@ -178,6 +178,9 @@ func ({{ $receiver }} *{{ $builder }}) sqlQuery(ctx context.Context) *sql.Select
selector = {{ $receiver }}.sql
selector.Select(selector.Columns(columns...)...)
}
if {{ $receiver }}.unique != nil && *{{ $receiver }}.unique {
selector.Distinct()
}
{{- /* Allow mutating the sql.Selector by ent extensions or user templates.*/}}
{{- with $tmpls := matchTemplate "dialect/sql/query/selector/*" }}
{{- range $tmpl := $tmpls }}