Class: ActiveRecord::Associations::Builder::HasOne

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

Overview

:nodoc:

Constant Summary

Constants inherited from Association

Association::VALID_OPTIONS

Class Method Summary collapse

Methods inherited from SingularAssociation

define_accessors, define_constructors

Methods inherited from Association

build, build_scope, check_dependent_options, create_reflection, define_accessors, define_callbacks, define_extensions, define_readers, define_writers, validate_options, wrap_scope

Class Method Details

.add_destroy_callbacks(model, reflection) ⇒ Object



17
18
19
# File 'lib/active_record/associations/builder/has_one.rb', line 17

def self.add_destroy_callbacks(model, reflection)
  super unless reflection.options[:through]
end

.define_validations(model, reflection) ⇒ Object



21
22
23
24
25
26
# File 'lib/active_record/associations/builder/has_one.rb', line 21

def self.define_validations(model, reflection)
  super
  if reflection.options[:required]
    model.validates_presence_of reflection.name, message: :required
  end
end

.macroObject



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

def self.macro
  :has_one
end

.valid_dependent_optionsObject



13
14
15
# File 'lib/active_record/associations/builder/has_one.rb', line 13

def self.valid_dependent_options
  [:destroy, :delete, :nullify, :restrict_with_error, :restrict_with_exception]
end

.valid_options(options) ⇒ Object



7
8
9
10
11
# File 'lib/active_record/associations/builder/has_one.rb', line 7

def self.valid_options(options)
  valid = super + [:as]
  valid += [:through, :source, :source_type] if options[:through]
  valid
end