From 6401a277cf8c548785425309bc6f95a7ee62ff27 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Thu, 22 Sep 2016 22:11:30 -0700 Subject: [PATCH] Be judicious about fkey naming --- text_helpers.go | 8 ++++---- text_helpers_test.go | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/text_helpers.go b/text_helpers.go index c340338..56451e6 100644 --- a/text_helpers.go +++ b/text_helpers.go @@ -196,7 +196,7 @@ func txtsFromToMany(tables []bdb.Table, table bdb.Table, rel bdb.ToManyRelations // fk == table = industry.Industry | industry.Industry // fk != table = industry.ParentIndustry | industry.Industry func txtNameToOne(fk bdb.ForeignKey) (localFn, foreignFn string) { - localFn = trimSuffixes(fk.Column) + localFn = strmangle.Singular(trimSuffixes(fk.Column)) fkeyIsTableName := localFn != strmangle.Singular(fk.ForeignTable) localFn = strmangle.TitleCase(localFn) @@ -235,8 +235,8 @@ func txtNameToOne(fk bdb.ForeignKey) (localFn, foreignFn string) { // fk != table = industry.MappedIndustryIndustry func txtNameToMany(toMany bdb.ToManyRelationship) (localFn, foreignFn string) { if toMany.ToJoinTable { - localFkey := trimSuffixes(toMany.JoinLocalColumn) - foreignFkey := trimSuffixes(toMany.JoinForeignColumn) + localFkey := strmangle.Singular(trimSuffixes(toMany.JoinLocalColumn)) + foreignFkey := strmangle.Singular(trimSuffixes(toMany.JoinForeignColumn)) if localFkey != strmangle.Singular(toMany.Table) { foreignFn = strmangle.TitleCase(localFkey) @@ -251,7 +251,7 @@ func txtNameToMany(toMany bdb.ToManyRelationship) (localFn, foreignFn string) { return localFn, foreignFn } - fkeyName := trimSuffixes(toMany.ForeignColumn) + fkeyName := strmangle.Singular(trimSuffixes(toMany.ForeignColumn)) if fkeyName != strmangle.Singular(toMany.Table) { localFn = strmangle.TitleCase(fkeyName) } diff --git a/text_helpers_test.go b/text_helpers_test.go index 3d494b9..b203dd9 100644 --- a/text_helpers_test.go +++ b/text_helpers_test.go @@ -190,6 +190,8 @@ func TestTxtNameToOne(t *testing.T) { {"jets", "jet_id", true, "jets", "id", true, "Jet", "Jet"}, {"jets", "plane_id", false, "jets", "id", true, "Plane", "PlaneJets"}, {"jets", "plane_id", true, "jets", "id", true, "Plane", "PlaneJet"}, + + {"race_result_scratchings", "results_id", false, "race_results", "id", true, "Result", "ResultRaceResultScratchings"}, } for i, test := range tests { @@ -237,6 +239,8 @@ func TestTxtNameToMany(t *testing.T) { {"pilots", "id", "pilots", "id", true, "pilot_id", "mentor_id", "MentorPilots", "Pilots"}, {"pilots", "id", "pilots", "id", true, "mentor_id", "pilot_id", "Pilots", "MentorPilots"}, {"pilots", "id", "pilots", "id", true, "captain_id", "mentor_id", "MentorPilots", "CaptainPilots"}, + + {"race_results", "id", "race_result_scratchings", "results_id", false, "", "", "ResultRaceResultScratchings", "Result"}, } for i, test := range tests {