mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
Implement has_one's embed ids include true
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user