From 929db1de2afa56dd8f3613deb9b89da4aee4a17b Mon Sep 17 00:00:00 2001 From: Aaron L Date: Thu, 14 Jul 2016 23:37:39 -0700 Subject: [PATCH] Fix error with to_many null foreign keys. --- templates_test/relationship_to_many.tpl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/templates_test/relationship_to_many.tpl b/templates_test/relationship_to_many.tpl index 617a682..3e0868e 100644 --- a/templates_test/relationship_to_many.tpl +++ b/templates_test/relationship_to_many.tpl @@ -18,10 +18,17 @@ func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) { boil.RandomizeStruct(&b, {{$rel.ForeignTable.NameSingular | camelCase}}DBTypes, true, "{{.ForeignColumn}}") boil.RandomizeStruct(&c, {{$rel.ForeignTable.NameSingular | camelCase}}DBTypes, true, "{{.ForeignColumn}}") + {{if .Nullable -}} + a.{{.Column | titleCase}}.Valid = true + {{- end}} + {{- if .ForeignColumnNullable -}} + b.{{.ForeignColumn | titleCase}}.Valid = true + c.{{.ForeignColumn | titleCase}}.Valid = true + {{- end}} {{if not .ToJoinTable -}} b.{{$rel.Function.ForeignAssignment}} = a.{{$rel.Function.LocalAssignment}} c.{{$rel.Function.ForeignAssignment}} = a.{{$rel.Function.LocalAssignment}} - {{end -}} + {{- end}} if err = b.InsertX(tx); err != nil { t.Fatal(err) }