From fc5bbc3e2ee334c74f27fe7a4b2694f21ec5708d Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sat, 16 Jul 2016 13:02:09 -0700 Subject: [PATCH 1/2] Use the cached relationship information --- templates.go | 1 - templates/05_relationship_to_many.tpl | 2 +- templates_test/relationship_to_many.tpl | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/templates.go b/templates.go index eaa0681..2ee3fd0 100644 --- a/templates.go +++ b/templates.go @@ -152,6 +152,5 @@ var templateFunctions = template.FuncMap{ "columnNames": bdb.ColumnNames, "columnTypes": bdb.ColumnTypes, "columnDBTypes": bdb.ColumnDBTypes, - "toManyRelationships": bdb.ToManyRelationships, "defaultValues": bdb.DefaultValues, } diff --git a/templates/05_relationship_to_many.tpl b/templates/05_relationship_to_many.tpl index 00a7b14..28debc6 100644 --- a/templates/05_relationship_to_many.tpl +++ b/templates/05_relationship_to_many.tpl @@ -2,7 +2,7 @@ {{- else -}} {{- $dot := . }} {{- $table := .Table }} - {{- range toManyRelationships .Table.Name .Tables -}} + {{- range .Table.ToManyRelationships -}} {{- $rel := textsFromRelationship $dot.Tables $table . -}} // {{$rel.Function.Name}} retrieves all the {{$rel.LocalTable.NameSingular}}'s {{$rel.ForeignTable.NameHumanReadable}} {{- if not (eq $rel.Function.Name $rel.ForeignTable.NamePluralGo)}} via {{.ForeignColumn}} column{{- end}}. diff --git a/templates_test/relationship_to_many.tpl b/templates_test/relationship_to_many.tpl index 3e0868e..5848a0a 100644 --- a/templates_test/relationship_to_many.tpl +++ b/templates_test/relationship_to_many.tpl @@ -2,7 +2,7 @@ {{- else -}} {{- $dot := . }} {{- $table := .Table }} - {{- range toManyRelationships .Table.Name .Tables -}} + {{- range .Table.ToManyRelationships -}} {{- $rel := textsFromRelationship $dot.Tables $table . -}} func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) { var err error @@ -75,5 +75,5 @@ func Test{{$rel.LocalTable.NameGo}}ToMany{{$rel.Function.Name}}(t *testing.T) { } } -{{ end -}}{{- /* range */ -}} +{{end -}}{{- /* range */ -}} {{- end -}}{{- /* outer if join table */ -}} From e4ddb7e0a88c1167d719303fad50e6e4e9205c11 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sat, 16 Jul 2016 13:23:15 -0700 Subject: [PATCH 2/2] Fix Patrick's jackal test. --- text_helpers_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/text_helpers_test.go b/text_helpers_test.go index 1f247b3..a3f0c82 100644 --- a/text_helpers_test.go +++ b/text_helpers_test.go @@ -113,7 +113,7 @@ func TestTextsFromRelationship(t *testing.T) { expect.ForeignTable.NameSingular = "video" expect.ForeignTable.NamePluralGo = "Videos" expect.ForeignTable.NameHumanReadable = "videos" - expect.ForeignTable.Slice = "videoSlice" + expect.ForeignTable.Slice = "VideoSlice" expect.Function.Name = "Videos" expect.Function.Receiver = "u" @@ -133,7 +133,7 @@ func TestTextsFromRelationship(t *testing.T) { expect.ForeignTable.NameSingular = "notification" expect.ForeignTable.NamePluralGo = "Notifications" expect.ForeignTable.NameHumanReadable = "notifications" - expect.ForeignTable.Slice = "notificationSlice" + expect.ForeignTable.Slice = "NotificationSlice" expect.Function.Name = "Notifications" expect.Function.Receiver = "u" @@ -153,7 +153,7 @@ func TestTextsFromRelationship(t *testing.T) { expect.ForeignTable.NameSingular = "notification" expect.ForeignTable.NamePluralGo = "Notifications" expect.ForeignTable.NameHumanReadable = "notifications" - expect.ForeignTable.Slice = "notificationSlice" + expect.ForeignTable.Slice = "NotificationSlice" expect.Function.Name = "SourceNotifications" expect.Function.Receiver = "u" @@ -173,7 +173,7 @@ func TestTextsFromRelationship(t *testing.T) { expect.ForeignTable.NameSingular = "video" expect.ForeignTable.NamePluralGo = "Videos" expect.ForeignTable.NameHumanReadable = "videos" - expect.ForeignTable.Slice = "videoSlice" + expect.ForeignTable.Slice = "VideoSlice" expect.Function.Name = "Videos" expect.Function.Receiver = "u"