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