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

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

Instance Method Summary (collapse)

Instance Method Details

- (void) belongs_to(name, options = {}, &block)

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



55
56
57
# File 'lib/active_model/serializer/associations.rb', line 55

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

- (void) has_many(name, options = {}, &block)

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



44
45
46
# File 'lib/active_model/serializer/associations.rb', line 44

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

- (void) has_one(name, options = {}, &block)

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



66
67
68
# File 'lib/active_model/serializer/associations.rb', line 66

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

- (Object) inherited(base)



32
33
34
35
# File 'lib/active_model/serializer/associations.rb', line 32

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