@@ -109,6 +109,7 @@ def self.include_directive_from_options(options)
109
109
end
110
110
end
111
111
112
+ # @api private
112
113
def self . serialization_adapter_instance
113
114
@serialization_adapter_instance ||= ActiveModelSerializers ::Adapter ::Attributes
114
115
end
@@ -138,9 +139,7 @@ def success?
138
139
# associations, similar to how ActiveModel::Serializers::JSON is used
139
140
# in ActiveRecord::Base.
140
141
#
141
- # TODO: Move to here the Attributes adapter logic for
142
- # +serializable_hash_for_single_resource(options)+
143
- # and include <tt>ActiveModel::Serializers::JSON</tt>.
142
+ # TODO: Include <tt>ActiveModel::Serializers::JSON</tt>.
144
143
# So that the below is true:
145
144
# @param options [nil, Hash] The same valid options passed to `serializable_hash`
146
145
# (:only, :except, :methods, and :include).
@@ -164,10 +163,13 @@ def success?
164
163
# serializer.as_json(include: :posts)
165
164
# # Second level and higher order associations work as well:
166
165
# serializer.as_json(include: { posts: { include: { comments: { only: :body } }, only: :title } })
167
- def serializable_hash ( adapter_opts = nil )
168
- adapter_opts ||= { }
169
- adapter_opts = { include : '*' } . merge! ( adapter_opts )
170
- serialize ( adapter_opts )
166
+ def serializable_hash ( adapter_options = nil , options = { } , adapter_instance = self . class . serialization_adapter_instance )
167
+ adapter_options ||= { }
168
+ options [ :include_directive ] ||= ActiveModel ::Serializer . include_directive_from_options ( adapter_options )
169
+ cached_attributes = adapter_options [ :cached_attributes ] ||= { }
170
+ resource = cached_attributes ( options [ :fields ] , cached_attributes , adapter_instance )
171
+ relationships = resource_relationships ( adapter_options , options , adapter_instance )
172
+ resource . merge ( relationships )
171
173
end
172
174
alias to_hash serializable_hash
173
175
alias to_h serializable_hash
@@ -199,15 +201,6 @@ def read_attribute_for_serialization(attr)
199
201
end
200
202
end
201
203
202
- # @api private
203
- def serialize ( adapter_options , options = { } , adapter_instance = self . class . serialization_adapter_instance )
204
- options [ :include_directive ] ||= ActiveModel ::Serializer . include_directive_from_options ( adapter_options )
205
- cached_attributes = adapter_options [ :cached_attributes ] ||= { }
206
- resource = cached_attributes ( options [ :fields ] , cached_attributes , adapter_instance )
207
- relationships = resource_relationships ( adapter_options , options , adapter_instance )
208
- resource . merge ( relationships )
209
- end
210
-
211
204
# @api private
212
205
def resource_relationships ( adapter_options , options , adapter_instance )
213
206
relationships = { }
@@ -227,7 +220,7 @@ def relationship_value_for(association, adapter_options, adapter_instance)
227
220
association_object = association_serializer && association_serializer . object
228
221
return unless association_object
229
222
230
- relationship_value = association_serializer . serialize ( adapter_options , { } , adapter_instance )
223
+ relationship_value = association_serializer . serializable_hash ( adapter_options , { } , adapter_instance )
231
224
232
225
if association . options [ :polymorphic ] && relationship_value
233
226
polymorphic_type = association_object . class . name . underscore
0 commit comments