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

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

Instance Method Summary collapse

Instance Method Details

#belongs_to(name, options = {}, &block) ⇒ 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



53
54
55
# File 'lib/active_model/serializer/concerns/associations.rb', line 53

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

#has_many(name, options = {}, &block) ⇒ 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



42
43
44
# File 'lib/active_model/serializer/concerns/associations.rb', line 42

def has_many(name, options = {}, &block) # rubocop:disable Style/PredicateName
  associate(HasManyReflection.new(name, options, block))
end

#has_one(name, options = {}, &block) ⇒ 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



64
65
66
# File 'lib/active_model/serializer/concerns/associations.rb', line 64

def has_one(name, options = {}, &block) # rubocop:disable Style/PredicateName
  associate(HasOneReflection.new(name, options, block))
end

#inherited(base) ⇒ Object



30
31
32
33
# File 'lib/active_model/serializer/concerns/associations.rb', line 30

def inherited(base)
  super
  base._reflections = _reflections.dup
end