mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Add polymorphic key to utility method
This commit is contained in:
parent
da0c33f53c
commit
54d3f2edf0
@ -120,7 +120,7 @@ module ActiveModel
|
||||
def serialize(object, scope, context, options)
|
||||
if polymorphic?
|
||||
if object
|
||||
find_serializable(object, scope, context, options).as_json(:root => object.class.to_s.demodulize.underscore.to_sym)
|
||||
find_serializable(object, scope, context, options).as_json(:root => polymorphic_key(object))
|
||||
else
|
||||
{}
|
||||
end
|
||||
@ -131,10 +131,9 @@ module ActiveModel
|
||||
|
||||
|
||||
def serialize_ids(object, scope)
|
||||
|
||||
if polymorphic?
|
||||
{
|
||||
object.class.to_s.demodulize.underscore.to_sym => object.read_attribute_for_serialization(:id),
|
||||
polymorphic_key(object) => object.read_attribute_for_serialization(:id),
|
||||
}
|
||||
elsif object
|
||||
{ key => object.read_attribute_for_serialization(:id) }
|
||||
@ -142,6 +141,10 @@ module ActiveModel
|
||||
{ key => nil }
|
||||
end
|
||||
end
|
||||
|
||||
def polymorphic_key(object)
|
||||
object.class.to_s.demodulize.underscore.to_sym
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user