Be judicious about fkey naming
This commit is contained in:
parent
0530ba9227
commit
6401a277cf
2 changed files with 8 additions and 4 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue