mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-24 14:56:50 +00:00
use id methods
This commit is contained in:
parent
6780cd3df5
commit
a854c1b9dc
@ -355,6 +355,9 @@ module ActiveModel
|
|||||||
serializable_hashes = (hash[key] ||= [])
|
serializable_hashes = (hash[key] ||= [])
|
||||||
|
|
||||||
serializables.each do |serializable|
|
serializables.each do |serializable|
|
||||||
|
puts key
|
||||||
|
puts serializable.inspect
|
||||||
|
|
||||||
unless already_serialized.include? serializable.object
|
unless already_serialized.include? serializable.object
|
||||||
already_serialized[serializable.object] = true
|
already_serialized[serializable.object] = true
|
||||||
serializable_hashes << serializable.serializable_hash
|
serializable_hashes << serializable.serializable_hash
|
||||||
|
|||||||
@ -109,9 +109,12 @@ module ActiveModel
|
|||||||
def serialize_ids
|
def serialize_ids
|
||||||
# Use pluck or select_columns if available
|
# Use pluck or select_columns if available
|
||||||
# return collection.ids if collection.respond_to?(:ids)
|
# return collection.ids if collection.respond_to?(:ids)
|
||||||
|
if !option(:include) && associated_object.respond_to?(:pluck)
|
||||||
associated_object.map do |item|
|
associated_object.pluck(:id)
|
||||||
item.read_attribute_for_serialization(:id)
|
else
|
||||||
|
associated_object.map do |item|
|
||||||
|
item.read_attribute_for_serialization(:id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -161,15 +164,19 @@ module ActiveModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def serialize_ids
|
def serialize_ids
|
||||||
object = associated_object
|
if polymorphic?
|
||||||
|
if associated_object
|
||||||
if object && polymorphic?
|
{
|
||||||
{
|
:type => polymorphic_key,
|
||||||
:type => polymorphic_key,
|
:id => associated_object.read_attribute_for_serialization(:id)
|
||||||
:id => object.read_attribute_for_serialization(:id)
|
}
|
||||||
}
|
else
|
||||||
elsif object
|
nil
|
||||||
object.read_attribute_for_serialization(:id)
|
end
|
||||||
|
elsif source_serializer.object.respond_to?("#{name}_id")
|
||||||
|
source_serializer.object.send("#{name}_id")
|
||||||
|
elsif associated_object
|
||||||
|
associated_object.read_attribute_for_serialization(:id)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user