Module: ActiveModel::Serializer::Associations::ClassMethods

Defined in:
lib/active_model/serializer/associations.rb

Instance Method Summary collapse

Instance Method Details

#belongs_to(name, options = {}) ⇒ void

This method returns an undefined value.

Examples:

belongs_to :author, serializer: AuthorSerializer

Parameters:

  • name (Symbol)

    of the association

  • options (Hash<Symbol => any>) (defaults to: {})

    for the reflection



50
51
52
# File 'lib/active_model/serializer/associations.rb', line 50

def belongs_to(name, options = {})
  associate BelongsToReflection.new(name, options)
end

#has_many(name, options = {}) ⇒ void

This method returns an undefined value.

Examples:

has_many :comments, serializer: CommentSummarySerializer

Parameters:

  • name (Symbol)

    of the association

  • options (Hash<Symbol => any>) (defaults to: {})

    for the reflection



39
40
41
# File 'lib/active_model/serializer/associations.rb', line 39

def has_many(name, options = {})
  associate HasManyReflection.new(name, options)
end

#has_one(name, options = {}) ⇒ void

This method returns an undefined value.

Examples:

has_one :author, serializer: AuthorSerializer

Parameters:

  • name (Symbol)

    of the association

  • options (Hash<Symbol => any>) (defaults to: {})

    for the reflection



61
62
63
# File 'lib/active_model/serializer/associations.rb', line 61

def has_one(name, options = {})
  associate HasOneReflection.new(name, options)
end

#inherited(base) ⇒ Object



28
29
30
# File 'lib/active_model/serializer/associations.rb', line 28

def inherited(base)
  base._reflections = self._reflections.try(:dup) || []
end