mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
Ensure valid jsonapi when blank relationship (#1930)
If you specify include_data false, and do not have any links for this
relationship, we would output something like:
`{ relationships: { comments: {} } }`
This is not valid jsonapi. We will now render
`{ relationships: { comments: { meta: {} } } }`
Instead.
Relevant jsonapi spec: http://jsonapi.org/format/#document-resource-object-relationships
This commit is contained in:
parent
a032201a91
commit
a77dfdaa85
@ -9,6 +9,7 @@ Fixes:
|
||||
- [#1887](https://github.com/rails-api/active_model_serializers/pull/1887) Make the comment reflect what the function does (@johnnymo87)
|
||||
- [#1890](https://github.com/rails-api/active_model_serializers/issues/1890) Ensure generator inherits from ApplicationSerializer when available (@richmolj)
|
||||
- [#1922](https://github.com/rails-api/active_model_serializers/pull/1922) Make railtie an optional dependency in runtime (@ggpasqualino)
|
||||
- [#1930](https://github.com/rails-api/active_model_serializers/pull/1930) Ensure valid jsonapi when relationship has no links or data (@richmolj)
|
||||
|
||||
Features:
|
||||
|
||||
|
||||
@ -24,6 +24,7 @@ module ActiveModelSerializers
|
||||
|
||||
meta = meta_for(association)
|
||||
hash[:meta] = meta if meta
|
||||
hash[:meta] = {} if hash.empty?
|
||||
|
||||
hash
|
||||
end
|
||||
|
||||
@ -54,7 +54,7 @@ module ActiveModelSerializers
|
||||
end
|
||||
|
||||
def test_relationship_data_not_included
|
||||
test_relationship({}, options: { include_data: false })
|
||||
test_relationship({ meta: {} }, options: { include_data: false })
|
||||
end
|
||||
|
||||
def test_relationship_simple_link
|
||||
|
||||
Loading…
Reference in New Issue
Block a user