Class: ActiveRecord::Associations::Builder::BelongsTo

Inherits:
SingularAssociation show all
Defined in:
activerecord/lib/active_record/associations/builder/belongs_to.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Association

#model, #name, #options, #scope

Instance Method Summary collapse

Methods inherited from SingularAssociation

#define_accessors, #define_constructors

Methods inherited from Association

build, #configure_dependency, #define_accessors, #define_readers, #define_writers, #initialize, #mixin, #validate_options

Constructor Details

This class inherits a constructor from ActiveRecord::Associations::Builder::Association

Instance Method Details

#buildObject



15
16
17
18
19
20
# File 'activerecord/lib/active_record/associations/builder/belongs_to.rb', line 15

def build
  reflection = super
  add_counter_cache_callbacks(reflection) if options[:counter_cache]
  add_touch_callbacks(reflection)         if options[:touch]
  reflection
end

#constructable?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'activerecord/lib/active_record/associations/builder/belongs_to.rb', line 11

def constructable?
  !options[:polymorphic]
end

#macroObject



3
4
5
# File 'activerecord/lib/active_record/associations/builder/belongs_to.rb', line 3

def macro
  :belongs_to
end

#valid_dependent_optionsObject



22
23
24
# File 'activerecord/lib/active_record/associations/builder/belongs_to.rb', line 22

def valid_dependent_options
  [:destroy, :delete]
end

#valid_optionsObject



7
8
9
# File 'activerecord/lib/active_record/associations/builder/belongs_to.rb', line 7

def valid_options
  super + [:foreign_type, :polymorphic, :touch]
end