Sha256: 732fab02616158fcdded0c441569244308510b6440ce4be908780901fe6e3cfc

Contents?: true

Size: 740 Bytes

Versions: 53

Compression:

Stored size: 740 Bytes

Contents

module ActiveRecord::Associations::Builder # :nodoc:
  class HasOne < SingularAssociation #:nodoc:
    def self.macro
      :has_one
    end

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

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

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

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

Version data entries

53 entries across 53 versions & 4 rubygems

Version Path
activerecord-5.1.7 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.7.rc1 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.6.2 lib/active_record/associations/builder/has_one.rb
activerecord-5.0.7.2 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.6.1 lib/active_record/associations/builder/has_one.rb
activerecord-5.0.7.1 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.6 lib/active_record/associations/builder/has_one.rb
activerecord-5.0.7 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.5 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.5.rc1 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.4 lib/active_record/associations/builder/has_one.rb
activerecord-5.0.6 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.4.rc1 lib/active_record/associations/builder/has_one.rb
activerecord-5.0.6.rc1 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.3 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.3.rc3 lib/active_record/associations/builder/has_one.rb
activerecord-5.0.5 lib/active_record/associations/builder/has_one.rb
activerecord-5.0.5.rc2 lib/active_record/associations/builder/has_one.rb
activerecord-5.1.3.rc2 lib/active_record/associations/builder/has_one.rb
activerecord-5.0.5.rc1 lib/active_record/associations/builder/has_one.rb