Easier to work with polymorphic interface

This commit is contained in:
twinturbo
2012-08-25 17:39:39 +02:00
parent 655c4fe1c2
commit 38859d1f3d
2 changed files with 17 additions and 8 deletions

View File

@@ -267,7 +267,10 @@ module ActiveModel
object = associated_object
if object && polymorphic?
{ polymorphic_key => find_serializable(object).serializable_hash }
{
:type => polymorphic_key,
polymorphic_key => find_serializable(object).serializable_hash
}
elsif object
find_serializable(object).serializable_hash
end
@@ -283,7 +286,10 @@ module ActiveModel
object = associated_object
if object && polymorphic?
{ polymorphic_key => object.read_attribute_for_serialization(:id) }
{
:type => polymorphic_key,
:id => object.read_attribute_for_serialization(:id)
}
elsif object
object.read_attribute_for_serialization(:id)
else