Skip to content

Commit bf4b4cd

Browse files
authored
Fix empty relationships on included resources (#1372)
JSONAPI::ResourceTree#load_included was failing to correctly populate the resource fragments of included resources, such that the `include_related` parameter was null. This was resulting in the relationships object lacking a data attribute for nil or empty resources. The JSON-API specification states that a null or empty array should be returned in these circumstances: https://jsonapi.org/format/#document-resource-object-linkage The underlying issue appears to be the use of `include_related` rather than the symbol `:include_related` when initializing nested resource fragments.
1 parent 695bb7c commit bf4b4cd

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/jsonapi/resource_tree.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def load_included(resource_klass, source_resource_tree, include_related, options
8585
find_related_resource_options)
8686

8787
related_resource_tree = source_resource_tree.get_related_resource_tree(relationship)
88-
related_resource_tree.add_resource_fragments(related_fragments, include_related[key][include_related])
88+
related_resource_tree.add_resource_fragments(related_fragments, include_related[key][:include_related])
8989

9090
# Now recursively get the related resources for the currently found resources
9191
load_included(relationship.resource_klass,

test/controllers/controller_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4371,7 +4371,8 @@ def test_complex_includes_things_nested_things
43714371
"links" => {
43724372
"self" => "http://test.host/api/things/40/relationships/things",
43734373
"related" => "http://test.host/api/things/40/things"
4374-
}
4374+
},
4375+
"data"=>[]
43754376
}
43764377
}
43774378
},

0 commit comments

Comments
 (0)