diff --git a/main.go b/main.go index ca01cf7..65e46f6 100644 --- a/main.go +++ b/main.go @@ -14,7 +14,7 @@ import ( "github.com/vattle/sqlboiler/boilingcore" ) -const sqlBoilerVersion = "2.4.0" +const sqlBoilerVersion = "2.4.1" var ( cmdState *boilingcore.State diff --git a/queries/query.go b/queries/query.go index 8c2abdb..06f06a3 100644 --- a/queries/query.go +++ b/queries/query.go @@ -188,6 +188,11 @@ func SetSelect(q *Query, sel []string) { q.selectCols = sel } +// GetSelect from the query +func GetSelect(q *Query) []string { + return q.selectCols +} + // SetCount on the query. func SetCount(q *Query) { q.count = true diff --git a/templates/06_relationship_to_many.tpl b/templates/06_relationship_to_many.tpl index 494461c..47c71b2 100644 --- a/templates/06_relationship_to_many.tpl +++ b/templates/06_relationship_to_many.tpl @@ -15,10 +15,7 @@ func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod // {{$txt.Function.Name}} retrieves all the {{.ForeignTable | singular}}'s {{$txt.ForeignTable.NameHumanReadable}} with an executor {{- if not (eq $txt.Function.Name $txt.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}. func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) {{$varNameSingular}}Query { - queryMods := []qm.QueryMod{ - qm.Select("{{$schemaForeignTable}}.*"), - } - + var queryMods []qm.QueryMod if len(mods) != 0 { queryMods = append(queryMods, mods...) } @@ -37,6 +34,11 @@ func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}(exec boil.Executor, query := {{$txt.ForeignTable.NamePluralGo}}(exec, queryMods...) queries.SetFrom(query.Query, "{{$schemaForeignTable}}") + + if len(queries.GetSelect(query.Query)) == 0 { + queries.SetSelect(query.Query, []string{"{{$schemaForeignTable}}.*"}) + } + return query }