diff --git a/lib/noosfero/core_ext/active_record/reflection.rb b/lib/noosfero/core_ext/active_record/reflection.rb index 1eb2b3c..dd9a113 100644 --- a/lib/noosfero/core_ext/active_record/reflection.rb +++ b/lib/noosfero/core_ext/active_record/reflection.rb @@ -1,28 +1,20 @@ + # on STI classes tike Article and Profile, plugins' extensions # on associations should be reflected on descendants module ActiveRecord - module Associations - def association(name) #:nodoc: - association = association_instance_get(name) - - if association.nil? - reflection = self.class._reflect_on_association(name) + module Reflection - # Check inheritance chain for possible upstream association - klass = self.class.superclass - while reflection.nil? && klass.respond_to?(:_reflect_on_association) - reflection = klass._reflect_on_association(name) - klass = klass.superclass - end + class << self - unless reflection - raise AssociationNotFoundError.new(self, name) - end - association = reflection.association_class.new(self, reflection) - association_instance_set(name, association) + def add_reflection_with_descendants(ar, name, reflection) + self.add_reflection_without_descendants ar, name, reflection + ar.descendants.each do |k| + k._reflections.merge!(name.to_s => reflection) + end if ar.base_class == ar end - association + alias_method_chain :add_reflection, :descendants + end end end -- libgit2 0.21.2