mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Extract id_key to a method
This commit is contained in:
parent
a41de0286f
commit
9f5e872621
@ -69,7 +69,7 @@ module ActiveModel
|
||||
if key = options[:key]
|
||||
key
|
||||
elsif embed_ids?
|
||||
"#{@name.to_s.singularize}_ids".to_sym
|
||||
id_key
|
||||
else
|
||||
@name
|
||||
end
|
||||
@ -83,6 +83,10 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
def id_key
|
||||
"#{@name.to_s.singularize}_ids".to_sym
|
||||
end
|
||||
|
||||
def serialize
|
||||
associated_object.map do |item|
|
||||
find_serializable(item).serializable_hash
|
||||
@ -96,9 +100,8 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def serialize_ids
|
||||
ids_key = "#{@name.to_s.singularize}_ids".to_sym
|
||||
if !options[:embed_key] && !source_serializer.respond_to?(@name.to_s) && source_serializer.object.respond_to?(ids_key)
|
||||
source_serializer.object.read_attribute_for_serialization(ids_key)
|
||||
if !options[:embed_key] && !source_serializer.respond_to?(@name.to_s) && source_serializer.object.respond_to?(id_key)
|
||||
source_serializer.object.read_attribute_for_serialization(id_key)
|
||||
else
|
||||
associated_object.map do |item|
|
||||
item.read_attribute_for_serialization(embed_key)
|
||||
@ -134,7 +137,7 @@ module ActiveModel
|
||||
if key = options[:key]
|
||||
key
|
||||
elsif embed_ids? && !polymorphic?
|
||||
"#{@name}_id".to_sym
|
||||
id_key
|
||||
else
|
||||
@name
|
||||
end
|
||||
@ -148,6 +151,10 @@ module ActiveModel
|
||||
end
|
||||
end
|
||||
|
||||
def id_key
|
||||
"#{@name}_id".to_sym
|
||||
end
|
||||
|
||||
def polymorphic_key
|
||||
associated_object.class.to_s.demodulize.underscore.to_sym
|
||||
end
|
||||
@ -172,8 +179,6 @@ module ActiveModel
|
||||
end
|
||||
|
||||
def serialize_ids
|
||||
id_key = "#{@name}_id".to_sym
|
||||
|
||||
if polymorphic?
|
||||
if associated_object
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user