mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Do not call send on associated objects, do it through elem.read_attribute_for_serialization
This commit is contained in:
parent
94a83c1cc0
commit
b9a6dfac2f
@ -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
|
||||
|
||||
|
||||
6
test/fixtures/poro.rb
vendored
6
test/fixtures/poro.rb
vendored
@ -4,11 +4,11 @@ class Model
|
||||
end
|
||||
|
||||
def read_attribute_for_serialization(name)
|
||||
if name == :id || name == 'id'
|
||||
object_id
|
||||
else
|
||||
@attributes[name]
|
||||
end
|
||||
|
||||
def id
|
||||
object_id
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user