Fix selecting in one-to-many relatiosships

- This fix checks the query that's being prepared for any select
  statements, if there's none then add one so the query does what's
  expected.
- Fix #159
This commit is contained in:
Aaron L 2017-06-14 20:53:39 -07:00
parent 1e9753091b
commit 35563d1bdf
3 changed files with 12 additions and 5 deletions

View file

@ -14,7 +14,7 @@ import (
"github.com/vattle/sqlboiler/boilingcore"
)
const sqlBoilerVersion = "2.4.0"
const sqlBoilerVersion = "2.4.1"
var (
cmdState *boilingcore.State

View file

@ -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

View file

@ -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
}