mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 07:16:49 +00:00
has_one returns arrays with roots pluralized
This commit is contained in:
@@ -164,7 +164,12 @@ end
|
||||
association.serializer_class <= ArraySerializer)
|
||||
associated_data.map { |elem| association.build_serializer(elem).serializable_hash }
|
||||
else
|
||||
association.build_serializer(associated_data).serializable_object
|
||||
serializable_obj = association.build_serializer(associated_data).serializable_object
|
||||
if !(association.serializer_class && association.serializer_class <= ArraySerializer)
|
||||
serializable_obj = [serializable_obj]
|
||||
serializable_obj.compact!
|
||||
end
|
||||
serializable_obj
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ module ActiveModel
|
||||
@embed_in_root = options.fetch(:embed_in_root) { options.fetch(:include) { CONFIG.embed_in_root } }
|
||||
@embed_key = options[:embed_key] || :id
|
||||
@key = options[:key]
|
||||
@embedded_key = options[:root] || name
|
||||
|
||||
self.serializer_class = @options[:serializer]
|
||||
end
|
||||
@@ -43,16 +42,18 @@ module ActiveModel
|
||||
end
|
||||
|
||||
class HasOne < Association
|
||||
def initialize(*args)
|
||||
def initialize(name, *args)
|
||||
super
|
||||
@key ||= "#{name}_id"
|
||||
@embedded_key = "#{@options[:root] || name}".pluralize
|
||||
@key ||= "#{name}_id"
|
||||
end
|
||||
end
|
||||
|
||||
class HasMany < Association
|
||||
def initialize(*args)
|
||||
def initialize(name, *args)
|
||||
super
|
||||
@key ||= "#{name.singularize}_ids"
|
||||
@embedded_key = @options[:root] || name
|
||||
@key ||= "#{name.to_s.singularize}_ids"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user