Class: DuckRecord::Associations::Builder::HasOne

Inherits:
SingularAssociation show all
Defined in:
lib/duck_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, create_reflection, define_accessors, define_callbacks, define_extensions, define_readers, define_writers, validate_options, wrap_scope

Class Method Details

.define_validations(model, reflection) ⇒ Object



13
14
15
16
17
18
# File 'lib/duck_record/associations/builder/has_one.rb', line 13

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/duck_record/associations/builder/has_one.rb', line 3

def self.macro
  :has_one
end

.valid_options(options) ⇒ Object



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

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