Fix another bug with one_to_one
This commit is contained in:
parent
7084ce6c9f
commit
43ec917a57
2 changed files with 37 additions and 2 deletions
|
@ -55,7 +55,11 @@ func textsFromForeignKey(packageName string, tables []bdb.Table, table bdb.Table
|
|||
|
||||
r.Function.PackageName = packageName
|
||||
r.Function.Name = strmangle.TitleCase(strmangle.Singular(strings.TrimSuffix(fkey.Column, "_id")))
|
||||
r.Function.ForeignName = mkFunctionName(strmangle.Singular(fkey.ForeignTable), strmangle.TitleCase(strmangle.Plural(fkey.Table)), fkey.Column, false)
|
||||
plurality := strmangle.Plural
|
||||
if fkey.Unique {
|
||||
plurality = strmangle.Singular
|
||||
}
|
||||
r.Function.ForeignName = mkFunctionName(strmangle.Singular(fkey.ForeignTable), strmangle.TitleCase(plurality(fkey.Table)), fkey.Column, false)
|
||||
r.Function.Varname = strmangle.CamelCase(strmangle.Singular(fkey.ForeignTable))
|
||||
r.Function.Receiver = strings.ToLower(table.Name[:1])
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ func TestTextsFromForeignKey(t *testing.T) {
|
|||
|
||||
expect.Function.PackageName = "models"
|
||||
expect.Function.Name = "Pilot"
|
||||
expect.Function.ForeignName = "Jets"
|
||||
expect.Function.ForeignName = "Jet"
|
||||
expect.Function.Varname = "pilot"
|
||||
expect.Function.Receiver = "j"
|
||||
expect.Function.ReverseInserts = false
|
||||
|
@ -45,6 +45,37 @@ func TestTextsFromForeignKey(t *testing.T) {
|
|||
if !reflect.DeepEqual(expect, texts) {
|
||||
t.Errorf("Want:\n%s\nGot:\n%s\n", spew.Sdump(expect), spew.Sdump(texts))
|
||||
}
|
||||
|
||||
texts = textsFromForeignKey("models", tables, jets, jets.FKeys[1])
|
||||
expect = RelationshipToOneTexts{}
|
||||
expect.ForeignKey = jets.FKeys[1]
|
||||
|
||||
expect.LocalTable.NameGo = "Jet"
|
||||
expect.LocalTable.ColumnNameGo = "AirportID"
|
||||
|
||||
expect.ForeignTable.Name = "airports"
|
||||
expect.ForeignTable.NameGo = "Airport"
|
||||
expect.ForeignTable.NamePluralGo = "Airports"
|
||||
expect.ForeignTable.ColumnName = "id"
|
||||
expect.ForeignTable.ColumnNameGo = "ID"
|
||||
|
||||
expect.Function.PackageName = "models"
|
||||
expect.Function.Name = "Airport"
|
||||
expect.Function.ForeignName = "Jets"
|
||||
expect.Function.Varname = "airport"
|
||||
expect.Function.Receiver = "j"
|
||||
expect.Function.ReverseInserts = false
|
||||
|
||||
expect.Function.LocalAssignment = "AirportID"
|
||||
expect.Function.ForeignAssignment = "ID"
|
||||
|
||||
if !reflect.DeepEqual(expect, texts) {
|
||||
t.Errorf("Want:\n%s\nGot:\n%s\n", spew.Sdump(expect), spew.Sdump(texts))
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(expect, texts) {
|
||||
t.Errorf("Want:\n%s\nGot:\n%s\n", spew.Sdump(expect), spew.Sdump(texts))
|
||||
}
|
||||
}
|
||||
|
||||
func TestTextsFromOneToOneRelationship(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue