mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Fix deserialization of polymorphic relationships (#2200)
* Classify the relationship type for polymorphic associations
This commit is contained in:
parent
715a702f55
commit
4d7c2457d7
@ -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:
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user