Serialize polymorphic id like a composite FK

This commit is contained in:
Adman65
2011-12-12 14:41:34 +01:00
parent 638614ffde
commit 1e32090477
2 changed files with 34 additions and 1 deletions

View File

@@ -112,7 +112,16 @@ module ActiveModel
end
def serialize_ids(object, scope)
object && object.read_attribute_for_serialization(:id)
return unless object
if polymorphic?
{
:id => object.read_attribute_for_serialization(:id),
"#{name}_type".to_sym => object.class.to_s.split('::').last
}
else
object.read_attribute_for_serialization(:id)
end
end
end
end