Implement has_one's embed ids include true

This commit is contained in:
Santiago Pastorino
2013-08-14 19:45:05 -03:00
parent 52bb3f6929
commit 516f5bdceb
3 changed files with 24 additions and 4 deletions

View File

@@ -74,7 +74,8 @@ module ActiveModel
self.class._associations.each_with_object({}) do |association, hash|
if association.embed_ids?
hash[association.key] = serialize_ids association
elsif association.embed_objects?
end
if association.embed_objects?
associated_data = send(association.name)
hash[association.embedded_key] = association.build_serializer(associated_data).serializable_hash
end

View File

@@ -13,7 +13,8 @@ module ActiveModel
@serializer_class = serializer.is_a?(String) ? serializer.constantize : serializer
end
attr_reader :name, :embed_ids, :embed_objects, :embed_key, :include
attr_reader :name, :embed_ids, :embed_objects, :embed_key
attr_accessor :include
alias embed_ids? embed_ids
alias embed_objects? embed_objects
alias include? include
@@ -23,6 +24,10 @@ module ActiveModel
@embed_objects = embed == :object || embed == :objects
end
def embed_objects?
@embed_objects || @embed_ids && @include
end
def build_serializer(object)
@serializer_class ||= Serializer.serializer_for(object)