123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Associations::Builder::SingularAssociation

Do not use. This class is for internal use only.
Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Association
Instance Chain:
self, Association
Inherits: ActiveRecord::Associations::Builder::Association
Defined in: activerecord/lib/active_record/associations/builder/singular_association.rb

Constant Summary

Association - Inherited

VALID_OPTIONS

Class Attribute Summary

Association - Inherited

Class Method Summary

Class Method Details

.define_accessors(model, reflection) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 11

def self.define_accessors(model, reflection)
  super
  mixin = model.generated_association_methods
  name = reflection.name

  define_constructors(mixin, name) unless reflection.polymorphic?

  mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
    def reload_#{name}
      association(:#{name}).force_reload_reader
    end

    def reset_#{name}
      association(:#{name}).reset
    end
  CODE
end

.define_constructors(mixin, name) (private)

Defines the (build|create)_association methods for belongs_to or has_one association

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 30

def self.define_constructors(mixin, name)
  mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
    def build_#{name}(*args, &block)
      association(:#{name}).build(*args, &block)
    end

    def create_#{name}(*args, &block)
      association(:#{name}).create(*args, &block)
    end

    def create_#{name}!(*args, &block)
      association(:#{name}).create!(*args, &block)
    end
  CODE
end

.valid_options(options) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/builder/singular_association.rb', line 7

def self.valid_options(options)
  super + [:required, :touch]
end