bug fix: was missing objects in sideload

This commit is contained in:
Sam Woodard 2015-07-10 14:31:26 -07:00
parent ffcbb660c3
commit 9b8432d9d9
2 changed files with 6 additions and 2 deletions

View File

@ -133,6 +133,10 @@ func TestUnmarshalNestedRelationshipsSideloaded(t *testing.T) {
if len(out.CurrentPost.Comments) != 2 {
t.Fatalf("Wrong number of comments")
}
if out.CurrentPost.Comments[0].Body != "foo" {
t.Fatalf("Comment body not set")
}
}
func unmarshalSamplePayload() (*Blog, error) {

View File

@ -178,10 +178,10 @@ func visitModelNode(model interface{}, sideload bool) (*Node, []*Node, error) {
return false
}
} else {
relationship, _, err := visitModelNode(fieldValue.Interface(), sideload)
relationship, inc, err := visitModelNode(fieldValue.Interface(), sideload)
if err == nil {
if sideload {
included = append(included, relationship)
included = append(included, inc...)
node.Relationships[args[1]] = &RelationshipOneNode{Data: toShallowNode(relationship)}
} else {
node.Relationships[args[1]] = &RelationshipOneNode{Data: relationship}