From e3398120275addca81260d0d541abb99f1fa0dae Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sun, 4 Jun 2017 12:29:04 -0700 Subject: [PATCH] Stop using aliases in the relationship select - This caused issues with mysql who doesn't understand the syntax: "delete from x as y where y.id = ?" --- templates/06_relationship_to_many.tpl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/templates/06_relationship_to_many.tpl b/templates/06_relationship_to_many.tpl index 10aa842..0e6e634 100644 --- a/templates/06_relationship_to_many.tpl +++ b/templates/06_relationship_to_many.tpl @@ -16,7 +16,7 @@ func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod {{- 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) {{$tableNameSingular}}Query { queryMods := []qm.QueryMod{ - qm.Select("{{id 0 | $dot.Quotes}}.*"), + qm.Select("{{$schemaForeignTable}}.*"), } if len(mods) != 0 { @@ -25,17 +25,18 @@ func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}(exec boil.Executor, {{if .ToJoinTable -}} queryMods = append(queryMods, - qm.InnerJoin("{{.JoinTable | $dot.SchemaTable}} as {{id 1 | $dot.Quotes}} on {{id 0 | $dot.Quotes}}.{{.ForeignColumn | $dot.Quotes}} = {{id 1 | $dot.Quotes}}.{{.JoinForeignColumn | $dot.Quotes}}"), - qm.Where("{{id 1 | $dot.Quotes}}.{{.JoinLocalColumn | $dot.Quotes}}=?", o.{{$txt.LocalTable.ColumnNameGo}}), + {{$schemaJoinTable := .JoinTable | $.SchemaTable -}} + qm.InnerJoin("{{$schemaJoinTable}} on {{$schemaForeignTable}}.{{.ForeignColumn | $dot.Quotes}} = {{$schemaJoinTable}}.{{.JoinForeignColumn | $dot.Quotes}}"), + qm.Where("{{$schemaJoinTable}}.{{.JoinLocalColumn | $dot.Quotes}}=?", o.{{$txt.LocalTable.ColumnNameGo}}), ) {{else -}} queryMods = append(queryMods, - qm.Where("{{id 0 | $dot.Quotes}}.{{.ForeignColumn | $dot.Quotes}}=?", o.{{$txt.LocalTable.ColumnNameGo}}), + qm.Where("{{$schemaForeignTable}}.{{.ForeignColumn | $dot.Quotes}}=?", o.{{$txt.LocalTable.ColumnNameGo}}), ) {{end}} query := {{$txt.ForeignTable.NamePluralGo}}(exec, queryMods...) - queries.SetFrom(query.Query, "{{$schemaForeignTable}} as {{id 0 | $dot.Quotes}}") + queries.SetFrom(query.Query, "{{$schemaForeignTable}}") return query }