Fix for bug with foreign keys mapping

This commit is contained in:
Vikram Rangnekar 2019-12-12 00:47:56 -05:00
parent 66055516d2
commit bf4c496756
1 changed files with 14 additions and 2 deletions

View File

@ -176,6 +176,7 @@ ORDER BY id;`
for rows.Next() { for rows.Next() {
c := DBColumn{} c := DBColumn{}
err = rows.Scan(&c.ID, &c.Name, &c.NotNull, &c.Type, &c.Array, &c.PrimaryKey, &c.UniqueKey, &c.FKeyTable, &c.fKeyColID) err = rows.Scan(&c.ID, &c.Name, &c.NotNull, &c.Type, &c.Array, &c.PrimaryKey, &c.UniqueKey, &c.FKeyTable, &c.fKeyColID)
if err != nil { if err != nil {
return nil, err return nil, err
@ -194,6 +195,17 @@ ORDER BY id;`
if c.Array { if c.Array {
v.Array = true v.Array = true
} }
if len(c.FKeyTable) != 0 {
v.FKeyTable = c.FKeyTable
}
if c.fKeyColID.Elements != nil {
v.fKeyColID = c.fKeyColID
err := v.fKeyColID.AssignTo(&v.FKeyColID)
if err != nil {
return nil, err
}
}
cmap[c.ID] = v
} else { } else {
err := c.fKeyColID.AssignTo(&c.FKeyColID) err := c.fKeyColID.AssignTo(&c.FKeyColID)
if err != nil { if err != nil {
@ -205,8 +217,8 @@ ORDER BY id;`
} }
cols := make([]DBColumn, 0, len(cmap)) cols := make([]DBColumn, 0, len(cmap))
for _, v := range cmap { for i := range cmap {
cols = append(cols, v) cols = append(cols, cmap[i])
} }
return cols, nil return cols, nil