mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 06:46:50 +00:00
Associations doesn't depend on source serializer anymore
This commit is contained in:
parent
460a250984
commit
5017fb686a
@ -392,6 +392,10 @@ module ActiveModel
|
|||||||
Associations::HasOne
|
Associations::HasOne
|
||||||
end
|
end
|
||||||
|
|
||||||
|
options[:value] ||= send(name)
|
||||||
|
options[:embed] = _embed unless options.key?(:embed)
|
||||||
|
options[:include] = _root_embed unless options.key?(:include)
|
||||||
|
options[:serializer_options] = self.options
|
||||||
association = association_class.new(name, self, options)
|
association = association_class.new(name, self, options)
|
||||||
|
|
||||||
if association.embed_ids?
|
if association.embed_ids?
|
||||||
|
|||||||
@ -38,19 +38,19 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def associated_object
|
def associated_object
|
||||||
option(:value) || source_serializer.send(name)
|
option(:value)
|
||||||
end
|
end
|
||||||
|
|
||||||
def embed_ids?
|
def embed_ids?
|
||||||
[:id, :ids].include? option(:embed, source_serializer._embed)
|
[:id, :ids].include? option(:embed)
|
||||||
end
|
end
|
||||||
|
|
||||||
def embed_objects?
|
def embed_objects?
|
||||||
[:object, :objects].include? option(:embed, source_serializer._embed)
|
[:object, :objects].include? option(:embed)
|
||||||
end
|
end
|
||||||
|
|
||||||
def embed_in_root?
|
def embed_in_root?
|
||||||
option(:include, source_serializer._root_embed)
|
option(:include)
|
||||||
end
|
end
|
||||||
|
|
||||||
def embeddable?
|
def embeddable?
|
||||||
@ -61,9 +61,9 @@ module ActiveModel
|
|||||||
|
|
||||||
def find_serializable(object)
|
def find_serializable(object)
|
||||||
if target_serializer
|
if target_serializer
|
||||||
target_serializer.new(object, source_serializer.options)
|
target_serializer.new(object, option(:serializer_options))
|
||||||
elsif object.respond_to?(:active_model_serializer) && (ams = object.active_model_serializer)
|
elsif object.respond_to?(:active_model_serializer) && (ams = object.active_model_serializer)
|
||||||
ams.new(object, source_serializer.options)
|
ams.new(object, option(:serializer_options))
|
||||||
else
|
else
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user