diff --git a/lib/json_api_client/resource.rb b/lib/json_api_client/resource.rb index 25c31775..87b6dd8f 100644 --- a/lib/json_api_client/resource.rb +++ b/lib/json_api_client/resource.rb @@ -494,8 +494,15 @@ def association_for(name) end end + def non_serializing_attributes + [ + self.class.read_only_attributes, + self.class.prefix_params.map(&:to_s) + ].flatten + end + def attributes_for_serialization - attributes.except(*self.class.read_only_attributes).slice(*changed) + attributes.except(*non_serializing_attributes).slice(*changed) end def relationships_for_serialization diff --git a/test/unit/serializing_test.rb b/test/unit/serializing_test.rb index 47290982..9fc14fca 100644 --- a/test/unit/serializing_test.rb +++ b/test/unit/serializing_test.rb @@ -6,6 +6,10 @@ class LimitedField < TestResource self.read_only_attributes += ['foo'] end + class NestedResource < TestResource + belongs_to :bar + end + class CustomSerializerAttributes < TestResource protected @@ -317,4 +321,19 @@ def test_underscored_relationship_key_serialization assert_equal expected, article.as_json_api['relationships'] end end + + def test_ensure_nested_path_params_not_serialized + resource = NestedResource.new(foo: 'bar', id: 1, bar_id: 99) + + expected = { + 'id' => 1, + 'type' => "nested_resources", + 'attributes' => { + 'foo' => 'bar' + } + } + + assert_equal expected, resource.as_json_api + end + end