2016-07-13 05:05:33 +02:00
|
|
|
{{- if .Table.IsJoinTable -}}
|
2016-07-14 05:31:44 +02:00
|
|
|
{{- else -}}
|
|
|
|
{{- $dot := . }}
|
|
|
|
{{- $table := .Table }}
|
|
|
|
{{- range toManyRelationships .Table.Name .Tables -}}
|
|
|
|
{{- $rel := textsFromRelationship $dot.Tables $table . -}}
|
|
|
|
func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) {
|
|
|
|
tx, err := boil.Begin()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer tx.Rollback()
|
|
|
|
|
|
|
|
var a {{$rel.LocalTable.NameGo}}
|
|
|
|
var b, c {{$rel.ForeignTable.NameGo}}
|
2016-07-13 05:05:33 +02:00
|
|
|
|
2016-07-14 05:31:44 +02:00
|
|
|
if err := a.InsertX(tx); err != nil {
|
2016-07-13 05:05:33 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2016-07-14 08:09:05 +02:00
|
|
|
boil.RandomizeStruct(&b, {{$rel.ForeignTable.NameSingular | camelCase}}DBTypes, true)
|
|
|
|
boil.RandomizeStruct(&c, {{$rel.ForeignTable.NameSingular | camelCase}}DBTypes, true)
|
2016-07-14 05:31:44 +02:00
|
|
|
b.{{$rel.Function.ForeignAssignment}} = a.{{$rel.Function.LocalAssignment}}
|
|
|
|
c.{{$rel.Function.ForeignAssignment}} = a.{{$rel.Function.LocalAssignment}}
|
|
|
|
if err := b.InsertX(tx); err != nil {
|
2016-07-13 05:05:33 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-07-14 05:31:44 +02:00
|
|
|
if err := c.InsertX(tx); err != nil {
|
2016-07-13 05:05:33 +02:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2016-07-14 05:31:44 +02:00
|
|
|
|
|
|
|
{{$varname := $rel.ForeignTable.NamePluralGo | toLower -}}
|
|
|
|
{{$varname}}, err := a.{{$rel.Function.Name}}X(tx)
|
|
|
|
|
|
|
|
bFound, cFound := false, false
|
|
|
|
for _, v := range {{$varname}} {
|
|
|
|
if v.{{$rel.Function.ForeignAssignment}} == b.{{$rel.Function.ForeignAssignment}} {
|
|
|
|
bFound = true
|
|
|
|
}
|
|
|
|
if v.{{$rel.Function.ForeignAssignment}} == c.{{$rel.Function.ForeignAssignment}} {
|
|
|
|
cFound = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bFound {
|
|
|
|
t.Error("expected to find b")
|
|
|
|
}
|
|
|
|
if !cFound {
|
|
|
|
t.Error("expected to find c")
|
|
|
|
}
|
|
|
|
|
|
|
|
if t.Failed() {
|
|
|
|
t.Logf("%#v", {{$varname}})
|
|
|
|
}
|
2016-07-13 05:05:33 +02:00
|
|
|
}
|
|
|
|
|
2016-07-14 05:31:44 +02:00
|
|
|
{{ end -}}{{- /* range */ -}}
|
2016-07-13 05:05:33 +02:00
|
|
|
{{- end -}}{{- /* outer if join table */ -}}
|