Fix ToMany.Func.ForeignName for renamed fkeys
This commit is contained in:
parent
0eea12fb75
commit
e46daf0991
2 changed files with 9 additions and 3 deletions
|
@ -146,7 +146,13 @@ func textsFromRelationship(tables []bdb.Table, table bdb.Table, rel bdb.ToManyRe
|
|||
|
||||
r.Function.Receiver = strings.ToLower(table.Name[:1])
|
||||
r.Function.Name = mkFunctionName(r.LocalTable.NameSingular, r.ForeignTable.NamePluralGo, rel.ForeignColumn, rel.ToJoinTable)
|
||||
r.Function.ForeignName = strmangle.TitleCase(strmangle.Plural(table.Name))
|
||||
plurality := strmangle.Singular
|
||||
foreignNamingColumn := rel.ForeignColumn
|
||||
if rel.ToJoinTable {
|
||||
plurality = strmangle.Plural
|
||||
foreignNamingColumn = rel.JoinLocalColumn
|
||||
}
|
||||
r.Function.ForeignName = strmangle.TitleCase(plurality(strings.TrimSuffix(foreignNamingColumn, "_id")))
|
||||
|
||||
if rel.Nullable {
|
||||
col := table.GetColumn(rel.Column)
|
||||
|
|
|
@ -150,7 +150,7 @@ func TestTextsFromRelationship(t *testing.T) {
|
|||
expect.ForeignTable.Slice = "JetSlice"
|
||||
|
||||
expect.Function.Name = "Jets"
|
||||
expect.Function.ForeignName = "Pilots"
|
||||
expect.Function.ForeignName = "Pilot"
|
||||
expect.Function.Receiver = "p"
|
||||
expect.Function.LocalAssignment = "ID"
|
||||
expect.Function.ForeignAssignment = "PilotID.Int"
|
||||
|
@ -173,7 +173,7 @@ func TestTextsFromRelationship(t *testing.T) {
|
|||
expect.ForeignTable.Slice = "LicenseSlice"
|
||||
|
||||
expect.Function.Name = "Licenses"
|
||||
expect.Function.ForeignName = "Pilots"
|
||||
expect.Function.ForeignName = "Pilot"
|
||||
expect.Function.Receiver = "p"
|
||||
expect.Function.LocalAssignment = "ID"
|
||||
expect.Function.ForeignAssignment = "PilotID"
|
||||
|
|
Loading…
Add table
Reference in a new issue