Commit 77b6d6b99275f06fb6aa79c77fbe7dc383f0e0ca
1 parent
da1968e4
Exists in
staging
and in
29 other branches
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>
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 | ... | ... |