Skip to content

Commit

Permalink
serialize_ids doesn't use source serializer and it's object
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed May 16, 2013
1 parent cec65a1 commit 87eadd0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
7 changes: 6 additions & 1 deletion lib/active_model/serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,12 @@ def include!(name, options={})
association = association_class.new(name, self, options)

if association.embed_ids?
node[association.key] = association.serialize_ids
node[association.key] =
if options[:embed_key] || self.respond_to?(name) || !self.object.respond_to?(association.id_key)
association.serialize_ids
else
self.object.read_attribute_for_serialization(association.id_key)
end

if association.embed_in_root? && hash.nil?
raise IncludeError.new(self.class, association.name)
Expand Down
23 changes: 7 additions & 16 deletions lib/active_model/serializer/associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,8 @@ def serializables
end

def serialize_ids
if !options[:embed_key] && !source_serializer.respond_to?(@name.to_s) && source_serializer.object.respond_to?(id_key)
source_serializer.object.read_attribute_for_serialization(id_key)
else
associated_object.map do |item|
item.read_attribute_for_serialization(embed_key)
end
associated_object.map do |item|
item.read_attribute_for_serialization(embed_key)
end
end
end
Expand Down Expand Up @@ -179,21 +175,16 @@ def serializables
end

def serialize_ids
if polymorphic?
if associated_object
if associated_object
id = associated_object.read_attribute_for_serialization(embed_key)
if polymorphic?
{
:type => polymorphic_key,
:id => associated_object.read_attribute_for_serialization(embed_key)
:id => id
}
else
nil
id
end
elsif !options[:embed_key] && !source_serializer.respond_to?(@name.to_s) && source_serializer.object.respond_to?(id_key)
source_serializer.object.read_attribute_for_serialization(id_key)
elsif associated_object
associated_object.read_attribute_for_serialization(embed_key)
else
nil
end
end
end
Expand Down

0 comments on commit 87eadd0

Please sign in to comment.