Add test for relationship to_one
This commit is contained in:
parent
6ddef6095e
commit
e78f19f3e9
1 changed files with 36 additions and 0 deletions
36
templates_test/relationship_to_one.tpl
Normal file
36
templates_test/relationship_to_one.tpl
Normal file
|
@ -0,0 +1,36 @@
|
|||
{{- if .Table.IsJoinTable -}}
|
||||
{{- else -}}
|
||||
{{- $dot := . -}}
|
||||
{{- range .Table.FKeys -}}
|
||||
{{- $rel := textsFromForeignKey $dot.Tables $dot.Table . -}}
|
||||
func Test{{$rel.LocalTable.NameGo}}ToOne{{$rel.ForeignTable.NameGo}}_{{$rel.LocalTable.ColumnNameGo}}(t *testing.T) {
|
||||
tx, err := boil.Begin()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
var foreign {{$rel.ForeignTable.NameGo}}
|
||||
var local {{$rel.LocalTable.NameGo}}
|
||||
|
||||
if err := foreign.InsertX(tx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.{{$rel.Function.LocalAssignment}} = foreign.{{$rel.Function.ForeignAssignment}}
|
||||
if err := local.InsertX(tx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
checkForeign, err := local.{{$rel.LocalTable.ColumnNameGo}}X(tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if checkForeign.{{$rel.Function.ForeignAssignment}} != foreign.{{$rel.Function.ForeignAssignment}} {
|
||||
t.Errorf("want: %v, got %v", foreign.{{$rel.Function.ForeignAssignment}}, checkForeign.{{$rel.Function.ForeignAssignment}})
|
||||
}
|
||||
}
|
||||
|
||||
{{end -}}
|
||||
{{- end -}}
|
Loading…
Add table
Reference in a new issue