has_one serialized objects shouldn't be wrapped in an array and it's key is singular

This commit is contained in:
Santiago Pastorino
2013-10-10 19:37:23 -02:00
parent 23e6ed32be
commit 4f70dc2091
4 changed files with 13 additions and 14 deletions

View File

@@ -152,7 +152,8 @@ module ActiveModel
if associated_data.respond_to?(:to_ary)
associated_data.map { |elem| association.build_serializer(elem).serializable_hash }
else
[association.build_serializer(associated_data).serializable_hash]
result = association.build_serializer(associated_data).serializable_hash
association.is_a?(Association::HasMany) ? [result] : result
end
end

View File

@@ -12,7 +12,7 @@ module ActiveModel
@embed_in_root = @embed_ids && (options[:include] || SETTINGS[:include])
@embed_key = options[:embed_key] || :id
@key = options[:key]
@embedded_key = options[:root]
@embedded_key = options[:root] || name
self.serializer_class = @options[:serializer]
end
@@ -41,7 +41,6 @@ module ActiveModel
def initialize(*args)
super
@key ||= "#{name}_id"
@embedded_key ||= name.pluralize
end
end
@@ -49,7 +48,6 @@ module ActiveModel
def initialize(*args)
super
@key ||= "#{name.singularize}_ids"
@embedded_key ||= name
end
end
end