Module: ActiveModel::Serializer::Associations

Extended by:
ActiveSupport::Concern
Included in:
ActiveModel::Serializer
Defined in:
lib/active_model/serializer/associations.rb

Overview

Defines an association in the object should be rendered.

The serializer object should implement the association name as a method which should return an array when invoked. If a method with the association name does not exist, the association name is dispatched to the serialized object.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#associationsEnumerator<Association>

Returns:



86
87
88
89
90
91
92
93
94
# File 'lib/active_model/serializer/associations.rb', line 86

def associations
  return unless object

  Enumerator.new do |y|
    self.class._reflections.each do |reflection|
      y.yield reflection.build_association(self, options)
    end
  end
end