Commit 6b693f8739d5af251ea70cd147c6b572669b189f
1 parent
3f84e761
Exists in
stable-spb-1.5
Revert "Fixes ActiveRecord relations for descendants"
This reverts commit 6607dc221143955c2b42f967c3e5d4de6948d1e9.
Showing
1 changed file
with
10 additions
and
18 deletions
Show diff stats
lib/noosfero/core_ext/active_record/reflection.rb
| 1 | + | |
| 1 | 2 | # on STI classes tike Article and Profile, plugins' extensions |
| 2 | 3 | # on associations should be reflected on descendants |
| 3 | 4 | module ActiveRecord |
| 4 | - module Associations | |
| 5 | - def association(name) #:nodoc: | |
| 6 | - association = association_instance_get(name) | |
| 7 | - | |
| 8 | - if association.nil? | |
| 9 | - reflection = self.class._reflect_on_association(name) | |
| 5 | + module Reflection | |
| 10 | 6 | |
| 11 | - # Check inheritance chain for possible upstream association | |
| 12 | - klass = self.class.superclass | |
| 13 | - while reflection.nil? && klass.respond_to?(:_reflect_on_association) | |
| 14 | - reflection = klass._reflect_on_association(name) | |
| 15 | - klass = klass.superclass | |
| 16 | - end | |
| 7 | + class << self | |
| 17 | 8 | |
| 18 | - unless reflection | |
| 19 | - raise AssociationNotFoundError.new(self, name) | |
| 20 | - end | |
| 21 | - association = reflection.association_class.new(self, reflection) | |
| 22 | - association_instance_set(name, association) | |
| 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 | |
| 23 | 14 | end |
| 24 | 15 | |
| 25 | - association | |
| 16 | + alias_method_chain :add_reflection, :descendants | |
| 17 | + | |
| 26 | 18 | end |
| 27 | 19 | end |
| 28 | 20 | end | ... | ... |