Add polymorphic key to utility method

This commit is contained in:
adman65 2012-01-03 13:26:47 +02:00
parent da0c33f53c
commit 54d3f2edf0

View File

@ -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