jinzhu/gorm — pull request #76 by tstranex (2014-03-15 20:04:17+00:00)
Title: Prevent panic for fields that implement sql.Scanner but aren't structs.

Hi

I ran into an issue when using a integer type as a field in my model. Here's an example:

type NamedInt int64

func (i *NamedInt) Scan(src interface{}) error {
v := reflect.ValueOf(src)
if v.Kind() != reflect.Int64 {
return errors.New("Cannot scan NamedInt from " + v.String())
}
*i = NamedInt(v.Int())
return nil
}

The model:

type Model struct {
NamedInt NamedInt `sql:"type:bigint"`
}

Currently, the presence of the NamedInt field causes gorm to panic. This change allows it to work as expected.