@@ -380,7 +380,7 @@ def serializable_hash(adapter_options = nil, options = {}, adapter_instance = se
380
380
adapter_options ||= { }
381
381
options [ :include_directive ] ||= ActiveModel ::Serializer . include_directive_from_options ( adapter_options )
382
382
resource = attributes_hash ( adapter_options , options , adapter_instance )
383
- relationships = resource_relationships ( adapter_options , options , adapter_instance )
383
+ relationships = associations_hash ( adapter_options , options , adapter_instance )
384
384
resource . merge ( relationships )
385
385
end
386
386
alias to_hash serializable_hash
@@ -423,34 +423,17 @@ def attributes_hash(_adapter_options, options, adapter_instance)
423
423
end
424
424
425
425
# @api private
426
- def resource_relationships ( adapter_options , options , adapter_instance )
426
+ def associations_hash ( adapter_options , options , adapter_instance )
427
427
relationships = { }
428
428
include_directive = options . fetch ( :include_directive )
429
429
associations ( include_directive ) . each do |association |
430
430
adapter_opts = adapter_options . merge ( include_directive : include_directive [ association . key ] )
431
- relationships [ association . key ] ||= relationship_value_for ( association , adapter_opts , adapter_instance )
431
+ relationships [ association . key ] ||= association . serializable_hash ( adapter_opts , adapter_instance )
432
432
end
433
433
434
434
relationships
435
435
end
436
436
437
- # @api private
438
- def relationship_value_for ( association , adapter_options , adapter_instance )
439
- return association . options [ :virtual_value ] if association . options [ :virtual_value ]
440
- association_serializer = association . serializer
441
- association_object = association_serializer && association_serializer . object
442
- return unless association_object
443
-
444
- relationship_value = association_serializer . serializable_hash ( adapter_options , { } , adapter_instance )
445
-
446
- if association . options [ :polymorphic ] && relationship_value
447
- polymorphic_type = association_object . class . name . underscore
448
- relationship_value = { type : polymorphic_type , polymorphic_type . to_sym => relationship_value }
449
- end
450
-
451
- relationship_value
452
- end
453
-
454
437
protected
455
438
456
439
attr_accessor :instance_options
0 commit comments