diff --git a/lib/active_model/serializer.rb b/lib/active_model/serializer.rb index 88f96d10..beff728a 100644 --- a/lib/active_model/serializer.rb +++ b/lib/active_model/serializer.rb @@ -160,9 +160,9 @@ module ActiveModel def serialize_ids(association) associated_data = send(association.name) 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 - associated_data.send(association.embed_key) if associated_data + associated_data.read_attribute_for_serialization(association.embed_key) if associated_data end end diff --git a/test/fixtures/poro.rb b/test/fixtures/poro.rb index e9d41da3..a43954b5 100644 --- a/test/fixtures/poro.rb +++ b/test/fixtures/poro.rb @@ -4,11 +4,11 @@ class Model end def read_attribute_for_serialization(name) - @attributes[name] - end - - def id - object_id + if name == :id || name == 'id' + object_id + else + @attributes[name] + end end end