09ed5709e5
- The old templates used to output \n\n after each run, with the previous changes this is no longer the case and as such the templates all must be formatted correctly.
43 lines
2.1 KiB
Smarty
43 lines
2.1 KiB
Smarty
{{- if .Table.IsJoinTable -}}
|
|
{{- else -}}
|
|
{{- $dot := . -}}
|
|
{{- $table := .Table -}}
|
|
{{- range .Table.ToManyRelationships -}}
|
|
{{- $varNameSingular := .ForeignTable | singular | camelCase -}}
|
|
{{- $txt := txtsFromToMany $dot.Tables $table . -}}
|
|
{{- $schemaForeignTable := .ForeignTable | $dot.SchemaTable}}
|
|
// {{$txt.Function.Name}}G retrieves all the {{.ForeignTable | singular}}'s {{$txt.ForeignTable.NameHumanReadable}}
|
|
{{- if not (eq $txt.Function.Name $txt.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}.
|
|
func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
|
|
return o.{{$txt.Function.Name}}(boil.GetDB(), mods...)
|
|
}
|
|
|
|
// {{$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("{{id 0 | $dot.Quotes}}.*"),
|
|
}
|
|
|
|
if len(mods) != 0 {
|
|
queryMods = append(queryMods, mods...)
|
|
}
|
|
|
|
{{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}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", o.{{$txt.LocalTable.ColumnNameGo}}),
|
|
)
|
|
{{else -}}
|
|
queryMods = append(queryMods,
|
|
qm.Where("{{id 0 | $dot.Quotes}}.{{.ForeignColumn | $dot.Quotes}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", o.{{$txt.LocalTable.ColumnNameGo}}),
|
|
)
|
|
{{end}}
|
|
|
|
query := {{$txt.ForeignTable.NamePluralGo}}(exec, queryMods...)
|
|
queries.SetFrom(query.Query, "{{$schemaForeignTable}} as {{id 0 | $dot.Quotes}}")
|
|
return query
|
|
}
|
|
|
|
{{end -}}{{- /* range relationships */ -}}
|
|
{{- end -}}{{- /* if isJoinTable */ -}}
|