paniced before when added Blog field to Post

This commit is contained in:
Sam Woodard 2015-07-20 16:10:52 -07:00
parent 853b80c07a
commit 23302de79c
3 changed files with 20 additions and 11 deletions

View File

@ -77,13 +77,17 @@ func unmarshalNode(data *Node, model reflect.Value, included *map[string]*Node)
return false
}
fieldValue := modelValue.Field(i)
fieldType := modelType.Field(i)
tag := fieldType.Tag.Get("jsonapi")
if tag == "" {
i += 1
return false
}
fieldValue := modelValue.Field(i)
i += 1
tag := fieldType.Tag.Get("jsonapi")
args := strings.Split(tag, ",")
if len(args) != 2 {

View File

@ -123,17 +123,21 @@ func visitModelNode(model interface{}, sideload bool) (*Node, []*Node, error) {
var i = 0
modelType.FieldByNameFunc(func(name string) bool {
fieldValue := modelValue.Field(i)
structField := modelType.Field(i)
i += 1
tag := structField.Tag.Get("jsonapi")
if tag == "" {
if er != nil {
return false
}
structField := modelType.Field(i)
tag := structField.Tag.Get("jsonapi")
if tag == "" {
i += 1
return false
}
fieldValue := modelValue.Field(i)
i += 1
args := strings.Split(tag, ",")
if len(args) != 2 {

View File

@ -19,6 +19,7 @@ type Blog struct {
}
type Post struct {
Blog
Id int `jsonapi:"primary,posts"`
BlogId int `jsonapi:"attr,blog_id"`
Title string `jsonapi:"attr,title"`