sqlboiler/templates/relationship_to_one_setops.tpl

32 lines
1.1 KiB
Smarty
Raw Normal View History

2016-08-26 08:50:45 +02:00
{{- define "relationship_to_one_setops_helper" -}}
{{- $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 {
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
}
{{- 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 -}}
{{- 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 -}}