go-bongo / bongo

Go ODM for MongoDB
MIT License
486 stars 40 forks source link

A reflection error when trying to set values on a pointer struct #5

Closed securingsincity closed 9 years ago

securingsincity commented 9 years ago

reflect: call of reflect.Value.FieldByName on zero Value when trying to save a value on a struct that is a pointer for example:

type BandsByRole struct {
    Foo     *Wrapper `bson:"foo"`
    Default *Wrapper `bson:"default"
}

type Wrapper struct {
  Bar BoolWrapper `bson: "bar"`
}

type BoolWrapper struct {
  Baz bool `bson:"baz"`
}

saving foo.bar.baz = true will throw the error

jraede commented 9 years ago

Oh @securingsincity that's just because you gotta instantiate the *Wrapper on the BandsByRole before setting it. What you're doing there is trying to set a value on a nil pointer that you haven't instantiated yet.

Sorry, I thought it was an issue with the diff tracker before but then I realized I already had a test for nil pointers and that was fine.