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


19
20
21
# File 'lib/active_record/associations/builder/has_one.rb', line 19

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

.define_validations(model, reflection) ⇒ Object


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

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

.macroObject


5
6
7
# File 'lib/active_record/associations/builder/has_one.rb', line 5

def self.macro
  :has_one
end

.valid_dependent_optionsObject


15
16
17
# File 'lib/active_record/associations/builder/has_one.rb', line 15

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

.valid_options(options) ⇒ Object


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

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