Class: ActiveModel::Serializer::Associations::HasMany
- Inherits:
-
Config
- Object
- Config
- ActiveModel::Serializer::Associations::HasMany
show all
- Defined in:
- lib/active_model/serializer/associations.rb
Overview
Instance Method Summary
collapse
Methods inherited from Config
#associated_object, #embed_ids?, #embed_in_root?, #embed_objects?, #embeddable?, #initialize, #name, #option, refine, #root, #source_serializer, #target_serializer
Instance Method Details
#embed_key ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/active_model/serializer/associations.rb', line 114
def embed_key
if key = option(:embed_key)
key
else
:id
end
end
|
#key ⇒ Object
104
105
106
107
108
109
110
111
112
|
# File 'lib/active_model/serializer/associations.rb', line 104
def key
if key = option(:key)
key
elsif embed_ids?
"#{@name.to_s.singularize}_ids".to_sym
else
@name
end
end
|
#serializables ⇒ Object
128
129
130
131
132
|
# File 'lib/active_model/serializer/associations.rb', line 128
def serializables
associated_object.map do |item|
find_serializable(item)
end
end
|
#serialize ⇒ Object
122
123
124
125
126
|
# File 'lib/active_model/serializer/associations.rb', line 122
def serialize
associated_object.map do |item|
find_serializable(item).serializable_hash
end
end
|
#serialize_ids ⇒ Object
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/active_model/serializer/associations.rb', line 134
def serialize_ids
ids_key = "#{@name.to_s.singularize}_ids".to_sym
if !option(: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)
else
associated_object.map do |item|
item.read_attribute_for_serialization(embed_key)
end
end
end
|