123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::Associations::NestedError

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActiveModel::NestedError
Defined in: activerecord/lib/active_record/associations/nested_error.rb

Constant Summary

::ActiveModel::Error - Inherited

CALLBACKS_OPTIONS, MESSAGE_OPTIONS

Class Attribute Summary

Class Method Summary

Instance Attribute Summary

::ActiveModel::NestedError - Inherited

::ActiveModel::Error - Inherited

#attribute

The attribute of base which the error belongs to.

#base

The object which the error belongs to.

#i18n_customize_full_message, #i18n_customize_full_message?,
#options

The options provided when calling errors#add.

#raw_type

The raw value provided as the second parameter when calling errors#add.

#type

The type of error, defaults to :invalid unless specified.

Instance Method Summary

::ActiveModel::Error - Inherited

#detail
#details

Returns the error details.

#eql?
#full_message

Returns the full error message.

#match?

See if error matches provided attribute, type, and options.

#message

Returns the error message.

#strict_match?

See if error matches provided attribute, type, and options exactly.

#attributes_for_hash, #==, #hash, #initialize_dup, #inspect

Constructor Details

.new(association, inner_error) ⇒ NestedError

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/nested_error.rb', line 8

def initialize(association, inner_error)
  @base = association.owner
  @association = association
  @inner_error = inner_error
  super(@base, inner_error, { attribute: compute_attribute(inner_error) })
end

Instance Attribute Details

#association (readonly, private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/nested_error.rb', line 16

attr_reader :association

Instance Method Details

#compute_attribute(inner_error) (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/nested_error.rb', line 18

def compute_attribute(inner_error)
  association_name = association.reflection.name

  if association.collection? && index_errors_setting && index
    "#{association_name}[#{index}].#{inner_error.attribute}".to_sym
  else
    "#{association_name}.#{inner_error.attribute}".to_sym
  end
end

#index (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/nested_error.rb', line 33

def index
  @index ||= ordered_records&.find_index(inner_error.base)
end

#index_errors_setting (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/nested_error.rb', line 28

def index_errors_setting
  @index_errors_setting ||=
    association.options.fetch(:index_errors, ActiveRecord.index_nested_attribute_errors)
end

#ordered_records (private)

[ GitHub ]

  
# File 'activerecord/lib/active_record/associations/nested_error.rb', line 37

def ordered_records
  case index_errors_setting
  when true # default is association order
    association.target
  when :nested_attributes_order
    association.nested_attributes_target
  end
end