2016-07-17 08:57:08 +02:00
|
|
|
{{- define "relationship_to_one_helper"}}
|
2016-08-01 07:10:10 +02:00
|
|
|
// {{.Function.Name}}G pointed to by the foreign key.
|
2016-08-02 05:37:58 +02:00
|
|
|
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}G(mods ...qm.QueryMod) (*{{.ForeignTable.NameGo}}, error) {
|
|
|
|
return {{.Function.Receiver}}.{{.Function.Name}}(boil.GetDB(), mods...)
|
2016-07-17 08:57:08 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
// {{.Function.Name}}GP pointed to by the foreign key. Panics on error.
|
2016-08-02 05:37:58 +02:00
|
|
|
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}GP(mods ...qm.QueryMod) *{{.ForeignTable.NameGo}} {
|
2016-08-05 07:03:37 +02:00
|
|
|
slice, err := {{.Function.Receiver}}.{{.Function.Name}}(boil.GetDB(), mods...)
|
2016-07-17 08:57:08 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
|
2016-08-05 07:03:37 +02:00
|
|
|
return slice
|
2016-07-09 19:14:07 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
// {{.Function.Name}}P pointed to by the foreign key with exeuctor. Panics on error.
|
2016-08-02 05:37:58 +02:00
|
|
|
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}P(exec boil.Executor, mods ...qm.QueryMod) *{{.ForeignTable.NameGo}} {
|
2016-08-05 07:03:37 +02:00
|
|
|
slice, err := {{.Function.Receiver}}.{{.Function.Name}}(exec, mods...)
|
2016-07-16 13:22:57 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
|
2016-08-05 07:03:37 +02:00
|
|
|
return slice
|
2016-07-16 13:22:57 +02:00
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
// {{.Function.Name}} pointed to by the foreign key.
|
2016-08-02 05:37:58 +02:00
|
|
|
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}(exec boil.Executor, mods ...qm.QueryMod) (*{{.ForeignTable.NameGo}}, error) {
|
2016-08-06 07:19:49 +02:00
|
|
|
queryMods := []qm.QueryMod{
|
|
|
|
qm.Where("{{.ForeignTable.ColumnName}}=$1", {{.Function.Receiver}}.{{.LocalTable.ColumnNameGo}}),
|
|
|
|
}
|
2016-06-20 01:00:37 +02:00
|
|
|
|
2016-08-02 05:37:58 +02:00
|
|
|
queryMods = append(queryMods, mods...)
|
2016-06-20 01:00:37 +02:00
|
|
|
|
2016-08-06 07:19:49 +02:00
|
|
|
query := {{.ForeignTable.NamePluralGo}}(exec, queryMods...)
|
|
|
|
boil.SetFrom(query.Query, "{{.ForeignTable.Name}}")
|
|
|
|
|
|
|
|
return query.One()
|
2016-06-20 01:00:37 +02:00
|
|
|
}
|
|
|
|
|
2016-07-17 08:57:08 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- if .Table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $dot := . -}}
|
|
|
|
{{- range .Table.FKeys -}}
|
|
|
|
{{- $rel := textsFromForeignKey $dot.PkgName $dot.Tables $dot.Table . -}}
|
|
|
|
{{- template "relationship_to_one_helper" $rel -}}
|
2016-06-20 01:00:37 +02:00
|
|
|
{{end -}}
|
|
|
|
{{- end -}}
|