Fix bug on FillStructWith so it ignores extra columns correctly

This bug was not being detected before because depending
on the order of the attributes on a map instance this test
would succeed by accident.

I was lucky enough to reproduce this error enough times to
understand it so it was possible to fix it.
pull/2/head
Vinícius Garcia 2021-01-12 22:34:46 -03:00
parent 247cdc0fd6
commit ea7a23f32f
1 changed files with 7 additions and 2 deletions

View File

@ -81,10 +81,15 @@ func FillStructWith(record interface{}, dbRow map[string]interface{}) error {
}
info := getCachedTagInfo(tagInfoCache, t)
for colName, rawSrc := range dbRow {
fieldIdx, found := info.Index[colName]
if !found {
// Ignore columns not tagged with `kissorm:""`
continue
}
src := NewPtrConverter(rawSrc)
dest := v.Field(info.Index[colName])
dest := v.Field(fieldIdx)
destType := t.Field(info.Index[colName]).Type
destValue, err := src.Convert(destType)