Commit ec7d0bc299acdbfb105f23172a2bd8321c9ff46a

Authored by Marcos Pereira
1 parent 6b693f87
Exists in stable-spb-1.5

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

Signed-off-by: Joenio Costa <joenio@colivre.coop.br>
Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
lib/noosfero/core_ext/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
... ...