Remove one-to-one
This commit is contained in:
parent
64284a7748
commit
81494a91d0
8 changed files with 17 additions and 70 deletions
|
@ -23,7 +23,6 @@ func ({{.Function.Receiver}} *{{.LocalTable.NameGo}}) {{.Function.Name}}(exec bo
|
|||
{{- end -}}{{/* end with */}}
|
||||
{{end -}}{{/* end define */}}
|
||||
|
||||
{{- /* Begin execution of template for one-to-one relationship */ -}}
|
||||
{{- if .Table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $dot := . -}}
|
||||
|
|
|
@ -1,18 +1,11 @@
|
|||
{{- /* Begin execution of template for many-to-one or many-to-many relationship helper */ -}}
|
||||
{{- if .Table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $dot := . -}}
|
||||
{{- $table := .Table -}}
|
||||
{{- range .Table.ToManyRelationships -}}
|
||||
{{- $varNameSingular := .ForeignTable | singular | camelCase -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- /* Begin execution of template for many-to-one relationship. */ -}}
|
||||
{{- $txt := textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table . -}}
|
||||
{{- template "relationship_to_one_helper" (preserveDot $dot $txt) -}}
|
||||
{{- else -}}
|
||||
{{- /* Begin execution of template for many-to-many relationship. */ -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- $schemaForeignTable := .ForeignTable | $dot.SchemaTable -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- $schemaForeignTable := .ForeignTable | $dot.SchemaTable -}}
|
||||
// {{$rel.Function.Name}}G retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}}
|
||||
{{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}.
|
||||
func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Name}}G(mods ...qm.QueryMod) {{$varNameSingular}}Query {
|
||||
|
@ -46,6 +39,5 @@ func ({{$rel.Function.Receiver}} *{{$rel.LocalTable.NameGo}}) {{$rel.Function.Na
|
|||
return query
|
||||
}
|
||||
|
||||
{{end -}}{{- /* if unique foreign key */ -}}
|
||||
{{- end -}}{{- /* range relationships */ -}}
|
||||
{{end -}}{{- /* range relationships */ -}}
|
||||
{{- end -}}{{- /* if isJoinTable */ -}}
|
||||
|
|
|
@ -86,7 +86,6 @@ func ({{$varNameSingular}}L) Load{{.Function.Name}}(e boil.Executor, singular bo
|
|||
{{- end -}}{{- /* end with */ -}}
|
||||
{{end -}}{{- /* end define */ -}}
|
||||
|
||||
{{- /* Begin execution of template for one-to-one eager load */ -}}
|
||||
{{- if .Table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $dot := . -}}
|
||||
|
|
|
@ -3,17 +3,11 @@
|
|||
{{- else -}}
|
||||
{{- $dot := . -}}
|
||||
{{- range .Table.ToManyRelationships -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- /* Begin execution of template for many-to-one eager load */ -}}
|
||||
{{- $txt := textsFromOneToOneRelationship $dot.PkgName $dot.Tables $dot.Table . -}}
|
||||
{{- template "relationship_to_one_eager_helper" (preserveDot $dot $txt) -}}
|
||||
{{- else -}}
|
||||
{{- /* Begin execution of template for many-to-many eager load */ -}}
|
||||
{{- $varNameSingular := $dot.Table.Name | singular | camelCase -}}
|
||||
{{- $txt := textsFromRelationship $dot.Tables $dot.Table . -}}
|
||||
{{- $arg := printf "maybe%s" $txt.LocalTable.NameGo -}}
|
||||
{{- $slice := printf "%sSlice" $txt.LocalTable.NameGo -}}
|
||||
{{- $schemaForeignTable := .ForeignTable | $dot.SchemaTable}}
|
||||
{{- $varNameSingular := $dot.Table.Name | singular | camelCase -}}
|
||||
{{- $txt := textsFromRelationship $dot.Tables $dot.Table . -}}
|
||||
{{- $arg := printf "maybe%s" $txt.LocalTable.NameGo -}}
|
||||
{{- $slice := printf "%sSlice" $txt.LocalTable.NameGo -}}
|
||||
{{- $schemaForeignTable := .ForeignTable | $dot.SchemaTable}}
|
||||
// Load{{$txt.Function.Name}} allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects.
|
||||
func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singular bool, {{$arg}} interface{}) error {
|
||||
|
@ -144,6 +138,5 @@ func ({{$varNameSingular}}L) Load{{$txt.Function.Name}}(e boil.Executor, singula
|
|||
return nil
|
||||
}
|
||||
|
||||
{{end -}}{{/* if ForeignColumnUnique */}}
|
||||
{{- end -}}{{/* range tomany */}}
|
||||
{{end -}}{{/* range tomany */}}
|
||||
{{- end -}}{{/* if IsJoinTable */}}
|
||||
|
|
|
@ -5,14 +5,9 @@
|
|||
{{- $table := .Table -}}
|
||||
{{- range .Table.ToManyRelationships -}}
|
||||
{{- $varNameSingular := .ForeignTable | singular | camelCase -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- /* Begin execution of template for many-to-one setops */ -}}
|
||||
{{- $txt := textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table . -}}
|
||||
{{- template "relationship_to_one_setops_helper" (preserveDot $dot $txt) -}}
|
||||
{{- else -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- $localNameSingular := .Table | singular | camelCase -}}
|
||||
{{- $foreignNameSingular := .ForeignTable | singular | camelCase}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- $localNameSingular := .Table | singular | camelCase -}}
|
||||
{{- $foreignNameSingular := .ForeignTable | singular | camelCase}}
|
||||
// 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 {{$rel.Function.Receiver}}.R.{{$rel.Function.Name}}.
|
||||
|
@ -219,6 +214,5 @@ func remove{{$rel.LocalTable.NameGo}}From{{$rel.ForeignTable.NameGo}}Slice({{$re
|
|||
}
|
||||
{{end -}}{{- /* if ToJoinTable */ -}}
|
||||
{{- end -}}{{- /* if nullable foreign key */ -}}
|
||||
{{- end -}}{{- /* if unique foreign key */ -}}
|
||||
{{- end -}}{{- /* range relationships */ -}}
|
||||
{{- end -}}{{- /* if IsJoinTable */ -}}
|
||||
|
|
|
@ -3,11 +3,7 @@
|
|||
{{- $dot := . }}
|
||||
{{- $table := .Table }}
|
||||
{{- range .Table.ToManyRelationships -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- $txt := textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table . -}}
|
||||
{{- template "relationship_to_one_test_helper" (preserveDot $dot $txt) -}}
|
||||
{{- else -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table .}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table .}}
|
||||
func test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
|
||||
var err error
|
||||
tx := MustTx(boil.Begin())
|
||||
|
@ -105,6 +101,5 @@ func test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
{{end -}}{{- /* if unique */ -}}
|
||||
{{- end -}}{{- /* range */ -}}
|
||||
{{end -}}{{- /* range */ -}}
|
||||
{{- end -}}{{- /* outer if join table */ -}}
|
||||
|
|
|
@ -3,13 +3,9 @@
|
|||
{{- $dot := . -}}
|
||||
{{- $table := .Table -}}
|
||||
{{- range .Table.ToManyRelationships -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- $txt := (textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table .) -}}
|
||||
{{- template "relationship_to_one_setops_test_helper" (preserveDot $dot $txt) -}}
|
||||
{{- else -}}
|
||||
{{- $varNameSingular := .Table | singular | camelCase -}}
|
||||
{{- $foreignVarNameSingular := .ForeignTable | singular | camelCase -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table .}}
|
||||
{{- $varNameSingular := .Table | singular | camelCase -}}
|
||||
{{- $foreignVarNameSingular := .ForeignTable | singular | camelCase -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table .}}
|
||||
func test{{$rel.LocalTable.NameGo}}ToManyAddOp{{$rel.Function.Name}}(t *testing.T) {
|
||||
var err error
|
||||
|
||||
|
@ -321,6 +317,5 @@ func test{{$rel.LocalTable.NameGo}}ToManyRemoveOp{{$rel.Function.Name}}(t *testi
|
|||
}
|
||||
}
|
||||
{{end -}}
|
||||
{{- end -}}{{- /* if unique foreign key */ -}}
|
||||
{{- end -}}{{- /* range relationships */ -}}
|
||||
{{- end -}}{{- /* outer if join table */ -}}
|
||||
|
|
|
@ -152,12 +152,7 @@ func TestToMany(t *testing.T) {
|
|||
{{- else -}}
|
||||
{{- range $table.ToManyRelationships -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- $oneToOne := textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table . -}}
|
||||
t.Run("{{$oneToOne.LocalTable.NameGo}}OneToOne{{$oneToOne.ForeignTable.NameGo}}_{{$oneToOne.Function.Name}}", test{{$oneToOne.LocalTable.NameGo}}ToOne{{$oneToOne.ForeignTable.NameGo}}_{{$oneToOne.Function.Name}})
|
||||
{{else -}}
|
||||
t.Run("{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}})
|
||||
{{end -}}{{- /* if unique */ -}}
|
||||
{{- end -}}{{- /* range */ -}}
|
||||
{{- end -}}{{- /* outer if join table */ -}}
|
||||
{{- end -}}{{- /* outer tables range */ -}}
|
||||
|
@ -205,10 +200,7 @@ func TestToManyAdd(t *testing.T) {
|
|||
{{- else -}}
|
||||
{{- range $table.ToManyRelationships -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- else -}}
|
||||
t.Run("{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToManyAddOp{{$rel.Function.Name}})
|
||||
{{end -}}{{- /* if unique */ -}}
|
||||
{{- end -}}{{- /* range */ -}}
|
||||
{{- end -}}{{- /* outer if join table */ -}}
|
||||
{{- end -}}{{- /* outer tables range */ -}}
|
||||
|
@ -226,12 +218,7 @@ func TestToManySet(t *testing.T) {
|
|||
{{- if not .ForeignColumnNullable -}}
|
||||
{{- else -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- $oneToOne := textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table . -}}
|
||||
t.Run("{{$oneToOne.LocalTable.NameGo}}OneToOne{{$oneToOne.ForeignTable.NameGo}}_{{$oneToOne.Function.Name}}", test{{$oneToOne.LocalTable.NameGo}}ToOneSetOp{{$oneToOne.ForeignTable.NameGo}}_{{$oneToOne.Function.Name}})
|
||||
{{else -}}
|
||||
t.Run("{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToManySetOp{{$rel.Function.Name}})
|
||||
{{end -}}{{- /* if unique */ -}}
|
||||
{{- end -}}{{- /* if foreign column nullable */ -}}
|
||||
{{- end -}}{{- /* range */ -}}
|
||||
{{- end -}}{{- /* outer if join table */ -}}
|
||||
|
@ -250,14 +237,7 @@ func TestToManyRemove(t *testing.T) {
|
|||
{{- if not .ForeignColumnNullable -}}
|
||||
{{- else -}}
|
||||
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
||||
{{- if (and .ForeignColumnUnique (not .ToJoinTable)) -}}
|
||||
{{- $oneToOne := textsFromOneToOneRelationship $dot.PkgName $dot.Tables $table . -}}
|
||||
{{- if or ($oneToOne.ForeignKey.Nullable) (and $oneToOne.Function.OneToOne $oneToOne.ForeignKey.ForeignColumnNullable)}}
|
||||
t.Run("{{$oneToOne.LocalTable.NameGo}}OneToOne{{$oneToOne.ForeignTable.NameGo}}_{{$oneToOne.Function.Name}}", test{{$oneToOne.LocalTable.NameGo}}ToOneRemoveOp{{$oneToOne.ForeignTable.NameGo}}_{{$oneToOne.Function.Name}})
|
||||
{{end -}}
|
||||
{{- else -}}
|
||||
t.Run("{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}", test{{$rel.LocalTable.NameGo}}ToManyRemoveOp{{$rel.Function.Name}})
|
||||
{{end -}}{{- /* if unique */ -}}
|
||||
{{- end -}}{{- /* if foreign column nullable */ -}}
|
||||
{{- end -}}{{- /* range */ -}}
|
||||
{{- end -}}{{- /* outer if join table */ -}}
|
||||
|
|
Loading…
Add table
Reference in a new issue