Started relationship set operations
This commit is contained in:
parent
2179570afd
commit
6ad467c259
4 changed files with 61 additions and 0 deletions
36
templates/relationship_to_many_setops.tpl
Normal file
36
templates/relationship_to_many_setops.tpl
Normal file
|
@ -0,0 +1,36 @@
|
|||
{{- if .Table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $dot := . -}}
|
||||
{{- $table := .Table -}}
|
||||
{{- range .Table.ToManyRelationships -}}
|
||||
{{- $varNameSingular := .ForeignTable | singular | camelCase -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- template "relationship_to_one_setops_helper" (textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table .) -}}
|
||||
{{- else -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
// Add{{$rel.Function.Name}} adds the given related objects to the existing relationships
|
||||
// of the {{$table.Name | singular}}, optionally inserting them as new records.
|
||||
// Appends related to R.{{$rel.Function.Name}}.
|
||||
func (r *{{$rel.LocalTable.NameGo}}Loaded) Add{{$rel.Function.Name}}(exec boil.Executor, insert bool, related ...*{{$rel.ForeignTable.NameGo}}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
{{if .ForeignColumnNullable -}}
|
||||
// Set{{$rel.Function.Name}} removes all previously related items of the
|
||||
// {{$table.Name | singular}} replacing them completely with the passed
|
||||
// in related items, optionally inserting them as new records.
|
||||
// Replaces R.{{$rel.Function.Name}} with related.
|
||||
func (r *{{$rel.LocalTable.NameGo}}Loaded) Set{{$rel.Function.Name}}(exec boil.Executor, insert bool, related ...*{{$rel.ForeignTable.NameGo}}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Remove{{$rel.Function.Name}} relationships from objects passed in.
|
||||
// Removes related items from R.{{$rel.Function.Name}}.
|
||||
func (r *{{$rel.LocalTable.NameGo}}Loaded) Remove{{$rel.Function.Name}}(exec boil.Executor, related ...*{{$rel.ForeignTable.NameGo}}) error {
|
||||
return nil
|
||||
}
|
||||
{{end -}}
|
||||
|
||||
{{end -}}{{- /* if unique foreign key */ -}}
|
||||
{{- end -}}{{- /* range relationships */ -}}
|
||||
{{- end -}}{{- /* outer if join table */ -}}
|
25
templates/relationship_to_one_setops.tpl
Normal file
25
templates/relationship_to_one_setops.tpl
Normal file
|
@ -0,0 +1,25 @@
|
|||
{{- define "relationship_to_one_setops_helper" -}}
|
||||
{{- $varNameSingular := .ForeignKey.ForeignTable | singular | camelCase -}}
|
||||
// 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 {
|
||||
return nil
|
||||
}
|
||||
|
||||
{{if .ForeignKey.Nullable -}}
|
||||
// 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 -}}
|
||||
{{- 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 -}}
|
0
templates_test/relationship_to_many_setops.tpl
Normal file
0
templates_test/relationship_to_many_setops.tpl
Normal file
0
templates_test/relationship_to_one_setops.tpl
Normal file
0
templates_test/relationship_to_one_setops.tpl
Normal file
Loading…
Add table
Reference in a new issue