Closed
Description
I have a response where relationships
contains some data, but they're not included as a compound document.
{
"data": {
"id": "12345",
"type": "books",
"attributes": {
"title": "A title",
},
"relationships": {
"chapters": {
"data": [
{
"id": "123456",
"type": "chapters"
}
]
}
}
}
}
when I try to access book.chapters
I get NoMethodError: undefined method [] for nil:NilClass
#look in included data
if relationship_definitions.key?("data")
return last_result_set.included.data_for(method, relationship_definitions)
end
This code checks for the relationships array relationship_definitions.key?("data")
, and calls last_result_set.included
that returns
#<JsonApiClient::IncludedData:0x0055e4e47cf398 @data={}>
, which generates the exception above.
Why not checking the included data instead of the relationships only?
Here the backtrace:
json_api_client-1.3.0/lib/json_api_client/included_data.rb:43:in `record_for'
json_api_client-1.3.0/lib/json_api_client/included_data.rb:27:in `block in data_for'
json_api_client-1.3.0/lib/json_api_client/included_data.rb:26:in `map'
json_api_client-1.3.0/lib/json_api_client/included_data.rb:26:in `data_for'
json_api_client-1.3.0/lib/json_api_client/resource.rb:447:in `method_missing'
Metadata
Metadata
Assignees
Labels
No labels