-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return null resource object identifier for blank id #2119
Conversation
Also, fix test where attributes were included when id was "" ``` 1) Failure: ActionController::Serialization::AdapterSelectorTest#test_render_using_adapter_override [test/action_c$ntroller/adapter_selector_test.rb:53]: --- expected +++ actual @@ -1 +1 @@ -"{\"data\":{\"id\":\"\",\"type\":\"profiles\",\"attributes\":{\"name\":\"Name 1\",\"description\":\"Description 1\"}}}" +"{\"data\":null}" ```
@@ -295,20 +295,8 @@ def attributes_for(serializer, fields) | |||
|
|||
# {http://jsonapi.org/format/#document-resource-objects Document Resource Objects} | |||
def resource_object_for(serializer, include_slice = {}) | |||
resource_object = serializer.fetch(self) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored to data_for
to decrease method size, per style
@@ -322,7 +310,10 @@ def resource_object_for(serializer, include_slice = {}) | |||
# prs: | |||
# https://github.com/rails-api/active_model_serializers/pull/1247 | |||
# https://github.com/rails-api/active_model_serializers/pull/1018 | |||
resource_object[:links] = links if links.any? | |||
if (links = links_for(serializer)).any? | |||
resource_object ||= {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resource_object may be nil
what if i want to serialize an object via json_api adapter that doesn't have an ID? |
Fix regression from 6e41528 where relationships with null data shows up with
:data=>{:id=>"", :type=>"locations"}
Also, fix test where attributes were included when id was ""