Do not call send on associated objects, do it through elem.read_attribute_for_serialization

This commit is contained in:
Santiago Pastorino 2013-10-11 13:54:38 -02:00
parent 94a83c1cc0
commit b9a6dfac2f
2 changed files with 7 additions and 7 deletions

View File

@ -160,9 +160,9 @@ module ActiveModel
def serialize_ids(association) def serialize_ids(association)
associated_data = send(association.name) associated_data = send(association.name)
if associated_data.respond_to?(:to_ary) if associated_data.respond_to?(:to_ary)
associated_data.map { |elem| elem.send(association.embed_key) } associated_data.map { |elem| elem.read_attribute_for_serialization(association.embed_key) }
else else
associated_data.send(association.embed_key) if associated_data associated_data.read_attribute_for_serialization(association.embed_key) if associated_data
end end
end end

10
test/fixtures/poro.rb vendored
View File

@ -4,11 +4,11 @@ class Model
end end
def read_attribute_for_serialization(name) def read_attribute_for_serialization(name)
@attributes[name] if name == :id || name == 'id'
end object_id
else
def id @attributes[name]
object_id end
end end
end end