Fix deserialization of polymorphic relationships (#2200)

* Classify the relationship type for polymorphic associations
This commit is contained in:
Dennis Stumm 2017-10-08 00:03:38 +02:00 committed by Benjamin Fleischer
parent 715a702f55
commit 4d7c2457d7
4 changed files with 4 additions and 3 deletions

View File

@ -16,6 +16,7 @@ Features:
Fixes:
- [#2022](https://github.com/rails-api/active_model_serializers/pull/2022) Mutation of ActiveModelSerializers::Model now changes the attributes. Originally in [#1984](https://github.com/rails-api/active_model_serializers/pull/1984). (@bf4)
- [#2200](https://github.com/rails-api/active_model_serializers/pull/2200) Fix deserialization of polymorphic relationships. (@dennis95stumm)
Misc:

View File

@ -189,7 +189,7 @@ module ActiveModelSerializers
polymorphic = (options[:polymorphic] || []).include?(assoc_name.to_sym)
if polymorphic
hash["#{prefix_key}_type".to_sym] = assoc_data.present? ? assoc_data['type'] : nil
hash["#{prefix_key}_type".to_sym] = assoc_data.present? ? assoc_data['type'].classify : nil
end
hash

View File

@ -45,7 +45,7 @@ module ActionController
response = JSON.parse(@response.body)
expected = {
'restriction_for_id' => '67',
'restriction_for_type' => 'discounts',
'restriction_for_type' => 'Discount',
'restricted_to_id' => nil,
'restricted_to_type' => nil
}

View File

@ -125,7 +125,7 @@ module ActiveModelSerializers
src: 'http://example.com/images/productivity.png',
author_id: nil,
photographer_id: '9',
photographer_type: 'people',
photographer_type: 'Person',
comment_ids: %w(1 2)
}
assert_equal(expected, parsed_hash)