Method: ActiveType::NestedAttributes::Association#initialize

Defined in:
lib/active_type/nested_attributes/association.rb

#initialize(owner, target_name, options = {}) ⇒ Association

Returns a new instance of Association.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_type/nested_attributes/association.rb', line 11

def initialize(owner, target_name, options = {})
  options.assert_valid_keys(*valid_options)

  @owner = owner
  @target_name = target_name.to_sym
  @allow_destroy = options.fetch(:allow_destroy, false)
  @reject_if = options.delete(:reject_if)
  @options = options.dup

  @index_errors = case
                  when ActiveRecord::VERSION::MAJOR < 5
                    @options[:index_errors]
                  when ActiveRecord::VERSION::MAJOR < 7
                    @options[:index_errors] || ActiveRecord::Base.index_nested_attribute_errors
                  else
                    @options[:index_errors] || ActiveRecord.index_nested_attribute_errors
                  end
end