HasOne associations work

This commit is contained in:
Yehuda Katz
2012-01-11 12:26:49 -07:00
parent f9d0259340
commit dd0b56c748
2 changed files with 45 additions and 19 deletions

View File

@@ -316,13 +316,17 @@ module ActiveModel
serializer = options[:serializer]
scope = options[:scope]
association = Associations::HasMany.new(key, { :serializer => serializer })
if value.respond_to?(:to_ary)
association = Associations::HasMany.new(key, :serializer => serializer)
else
association = Associations::HasOne.new(key, :serializer => serializer)
end
if embed == :ids
node[key] = association.serialize_ids(value, scope)
if root_embed
merge_association hash, key, association.serialize_many(value, scope, self, {})
merge_association hash, association.plural_key, association.serialize_many(value, scope, self, {})
end
elsif embed == :objects
node[key] = association.serialize(value, scope)