2016-07-15 06:49:22 +02:00
|
|
|
{{- 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) {
|
2016-07-15 08:15:35 +02:00
|
|
|
tx := MustTx(boil.Begin())
|
2016-07-15 06:49:22 +02:00
|
|
|
defer tx.Rollback()
|
|
|
|
|
|
|
|
var foreign {{$rel.ForeignTable.NameGo}}
|
|
|
|
var local {{$rel.LocalTable.NameGo}}
|
2016-07-15 07:45:24 +02:00
|
|
|
{{if .Nullable -}}
|
|
|
|
local.{{.Column | titleCase}}.Valid = true
|
|
|
|
{{end}}
|
|
|
|
{{- if .ForeignColumnNullable -}}
|
|
|
|
foreign.{{.ForeignColumn | titleCase}}.Valid = true
|
|
|
|
{{end}}
|
2016-07-15 06:49:22 +02:00
|
|
|
|
|
|
|
if err := foreign.InsertX(tx); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-07-15 07:45:24 +02:00
|
|
|
local.{{$rel.Function.LocalAssignment}} = foreign.{{$rel.Function.ForeignAssignment}}
|
2016-07-15 06:49:22 +02:00
|
|
|
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 -}}
|