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.
|
|
|
|
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}G(selectCols ...string) (*{{.ForeignTable.NameGo}}, error) {
|
|
|
|
return {{.Function.Receiver}}.{{.Function.Name}}(boil.GetDB(), selectCols...)
|
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.
|
|
|
|
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}GP(selectCols ...string) *{{.ForeignTable.NameGo}} {
|
|
|
|
o, err := {{.Function.Receiver}}.{{.Function.Name}}(boil.GetDB(), selectCols...)
|
2016-07-17 08:57:08 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return o
|
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.
|
|
|
|
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}P(exec boil.Executor, selectCols ...string) *{{.ForeignTable.NameGo}} {
|
|
|
|
o, err := {{.Function.Receiver}}.{{.Function.Name}}(exec, selectCols...)
|
2016-07-16 13:22:57 +02:00
|
|
|
if err != nil {
|
|
|
|
panic(boil.WrapErr(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return o
|
|
|
|
}
|
|
|
|
|
2016-08-01 07:10:10 +02:00
|
|
|
// {{.Function.Name}} pointed to by the foreign key.
|
|
|
|
func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}(exec boil.Executor, selectCols ...string) (*{{.ForeignTable.NameGo}}, error) {
|
2016-07-17 08:57:08 +02:00
|
|
|
{{.Function.Varname}} := &{{.ForeignTable.NameGo}}{}
|
2016-06-20 01:00:37 +02:00
|
|
|
|
2016-07-15 06:48:59 +02:00
|
|
|
selectColumns := `*`
|
|
|
|
if len(selectCols) != 0 {
|
|
|
|
selectColumns = fmt.Sprintf(`"%s"`, strings.Join(selectCols, `","`))
|
|
|
|
}
|
|
|
|
|
2016-07-17 08:57:08 +02:00
|
|
|
query := fmt.Sprintf(`select %s from {{.ForeignTable.Name}} where "{{.ForeignTable.ColumnName}}" = $1`, selectColumns)
|
|
|
|
err := exec.QueryRow(query, {{.Function.Receiver}}.{{.LocalTable.ColumnNameGo}}).Scan(boil.GetStructPointers({{.Function.Varname}}, selectCols...)...)
|
2016-06-20 01:00:37 +02:00
|
|
|
if err != nil {
|
2016-07-17 08:57:08 +02:00
|
|
|
return nil, fmt.Errorf(`{{.Function.PackageName}}: unable to select from {{.ForeignTable.Name}}: %v`, err)
|
2016-06-20 01:00:37 +02:00
|
|
|
}
|
|
|
|
|
2016-07-17 08:57:08 +02:00
|
|
|
return {{.Function.Varname}}, nil
|
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 -}}
|