Module: AwesomeNestedSetOvveride::RelateParent

Defined in:
core/lib/spree/awesome_nested_set_override.rb

Overview

Add :polimorphic key option only when used to make it work with Rails 6.1+, required since rails/rails@2c008d9 This can be removed when upgrading to an awesome_nested_set version compliant with Rails 6.1+, already addressed in collectiveidea/awesome_nested_set#421

Instance Method Summary collapse

Instance Method Details

#acts_as_nested_set_relate_parent!Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'core/lib/spree/awesome_nested_set_override.rb', line 10

def acts_as_nested_set_relate_parent!
  # Disable Rubocop to keep original code for diffs
  # rubocop:disable
  options = {
    :class_name => self.base_class.to_s,
    :foreign_key => parent_column_name,
    :primary_key => primary_column_name,
    :counter_cache => acts_as_nested_set_options[:counter_cache],
    :inverse_of => (:children unless acts_as_nested_set_options[:polymorphic]),
    :touch => acts_as_nested_set_options[:touch]
  }
  options[:polymorphic] = true if acts_as_nested_set_options[:polymorphic]
  options[:optional] = true if ActiveRecord::VERSION::MAJOR >= 5
  belongs_to :parent, options
  # rubocop:enable
end