mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Move polymorphic type into the serializable_hash
This commit is contained in:
parent
9fa716e452
commit
638614ffde
@ -100,8 +100,12 @@ module ActiveModel
|
||||
return unless object
|
||||
|
||||
if polymorphic?
|
||||
polymorphic_type = object.class.to_s.split('::').last
|
||||
serializer_class = "#{object.class.to_s}Serializer".constantize
|
||||
serializer_class.new(object, scope).serializable_hash
|
||||
|
||||
serializer_class.new(object, scope).serializable_hash.merge({
|
||||
"#{name}_type".to_sym => polymorphic_type
|
||||
})
|
||||
else
|
||||
serializer.new(object, scope).serializable_hash
|
||||
end
|
||||
@ -294,8 +298,6 @@ module ActiveModel
|
||||
hash[association.key] = association.serialize(associated_object, scope)
|
||||
|
||||
if association.polymorphic? && associated_object
|
||||
polymorphic_type = associated_object.class.to_s.split('::').last
|
||||
hash["#{association.name}_type".to_sym] = polymorphic_type
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -703,8 +703,8 @@ class SerializerTest < ActiveModel::TestCase
|
||||
serializer = polymorphic_serializer.new(blog, user)
|
||||
|
||||
assert_equal({
|
||||
:writer_type => 'PolymorphicUser',
|
||||
:writer => {
|
||||
:writer_type => 'PolymorphicUser',
|
||||
:first_name => "Jose",
|
||||
:last_name => "Valim"
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user