Commit c06b49236ed3ef82eac79e0bbe03b5cef013c48e

Authored by Braulio Bhavamitra
2 parents 82dc3676 77b6d6b9

Merge branch 'fix_activerecord_relations_inheritance' into 'master'

Fixes ActiveRecord relations for descendants

Temporary fix, waiting for original fix to be merged.

Original author: Jon Moss
Merge Request: https://github.com/rails/rails/pull/24719
Issue: https://github.com/rails/rails/issues/20678

See merge request !914
Showing 1 changed file with 4 additions and 12 deletions   Show diff stats
lib/extensions/active_record/reflection.rb
1   -
2 1 # on STI classes tike Article and Profile, plugins' extensions
3 2 # on associations should be reflected on descendants
4 3 module ActiveRecord
5 4 module Reflection
6   -
7   - class << self
8   -
9   - def add_reflection_with_descendants(ar, name, reflection)
10   - self.add_reflection_without_descendants ar, name, reflection
11   - ar.descendants.each do |k|
12   - k._reflections.merge!(name.to_s => reflection)
13   - end if ar.base_class == ar
  5 + def self.add_reflection(ar, name, reflection)
  6 + (ar.descendants << ar).each do |klass|
  7 + klass.clear_reflections_cache
  8 + klass._reflections = klass._reflections.merge(name.to_s => reflection)
14 9 end
15   -
16   - alias_method_chain :add_reflection, :descendants
17   -
18 10 end
19 11 end
20 12 end
... ...