2016-08-26 08:50:45 +02:00
|
|
|
{{- define "relationship_to_one_setops_helper" -}}
|
2016-08-26 16:59:28 +02:00
|
|
|
{{- $varNameSingular := .ForeignKey.ForeignTable | singular | camelCase}}
|
|
|
|
|
2016-08-26 08:50:45 +02:00
|
|
|
// Set{{.Function.Name}} of the {{.ForeignKey.Table | singular}} to the related item.
|
|
|
|
// Sets R.{{.Function.Name}} to related.
|
|
|
|
func (r *{{.LocalTable.NameGo}}Loaded) Set{{.Function.Name}}(exec boil.Executor, insert bool, related *{{.ForeignTable.NameGo}}) error {
|
2016-08-26 16:59:28 +02:00
|
|
|
r.{{.Function.Name}} = related
|
|
|
|
r.{{.Function.Name}}.{{.Function.ForeignAssignment}} = 5
|
|
|
|
if insert {
|
|
|
|
return related.Insert()
|
|
|
|
}
|
|
|
|
|
|
|
|
return exec.Exec(`update "{{.ForeignKey.Table}}" set "{{.ForeignKey.Column}}" = $1`, 5)
|
2016-08-26 08:50:45 +02:00
|
|
|
}
|
2016-08-26 16:59:28 +02:00
|
|
|
{{- if .ForeignKey.Nullable}}
|
2016-08-26 08:50:45 +02:00
|
|
|
|
|
|
|
// Remove{{.Function.Name}} relationship.
|
|
|
|
// Sets R.{{.Function.Name}} to nil.
|
|
|
|
func (r *{{.LocalTable.NameGo}}Loaded) Remove{{.Function.Name}}(exec boil.Executor) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
{{end -}}
|
2016-08-26 16:59:28 +02:00
|
|
|
{{- end -}}
|
2016-08-26 08:50:45 +02:00
|
|
|
{{- if .Table.IsJoinTable -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $dot := . -}}
|
|
|
|
{{- range .Table.FKeys -}}
|
|
|
|
{{- $rel := textsFromForeignKey $dot.PkgName $dot.Tables $dot.Table . -}}
|
|
|
|
{{- template "relationship_to_one_setops_helper" $rel -}}
|
|
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|