sqlboiler/templates/04_relationship_to_one.tpl

27 lines
1,018 B
Smarty
Raw Normal View History

2016-09-18 20:13:11 +02:00
{{- if .Table.IsJoinTable -}}
{{- else -}}
{{- $dot := . -}}
{{- range .Table.FKeys -}}
2016-09-19 01:02:08 +02:00
{{- $txt := txtsFromFKey $dot.Tables $dot.Table . -}}
{{- $varNameSingular := .ForeignTable | singular | camelCase -}}
2016-09-18 20:13:11 +02:00
// {{$txt.Function.Name}}G pointed to by the foreign key.
2016-09-21 05:37:28 +02:00
func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
return o.{{$txt.Function.Name}}(boil.GetDB(), mods...)
}
2016-09-18 20:13:11 +02:00
// {{$txt.Function.Name}} pointed to by the foreign key.
2016-09-21 05:37:28 +02:00
func (o *{{$txt.LocalTable.NameGo}}) {{$txt.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) ({{$varNameSingular}}Query) {
queryMods := []qm.QueryMod{
2016-09-21 05:37:28 +02:00
qm.Where("{{$txt.ForeignTable.ColumnName}}={{if $dot.Dialect.IndexPlaceholders}}$1{{else}}?{{end}}", o.{{$txt.LocalTable.ColumnNameGo}}),
}
queryMods = append(queryMods, mods...)
2016-09-18 20:13:11 +02:00
query := {{$txt.ForeignTable.NamePluralGo}}(exec, queryMods...)
2016-09-21 06:05:26 +02:00
queries.SetFrom(query.Query, "{{.ForeignTable | $dot.SchemaTable}}")
2016-08-06 07:19:49 +02:00
return query
}
{{- end -}}
{{- end -}}