diff --git a/lib/noosfero/core_ext.rb b/lib/noosfero/core_ext.rb index ad34b3b..a935fa9 100644 --- a/lib/noosfero/core_ext.rb +++ b/lib/noosfero/core_ext.rb @@ -1,3 +1,5 @@ require 'noosfero/core_ext/string' require 'noosfero/core_ext/integer' require 'noosfero/core_ext/active_record' +require 'noosfero/core_ext/active_record/reflection' + diff --git a/lib/noosfero/core_ext/active_record/reflection.rb b/lib/noosfero/core_ext/active_record/reflection.rb new file mode 100644 index 0000000..dd9a113 --- /dev/null +++ b/lib/noosfero/core_ext/active_record/reflection.rb @@ -0,0 +1,20 @@ + +# on STI classes tike Article and Profile, plugins' extensions +# on associations should be reflected on descendants +module ActiveRecord + module Reflection + + class << self + + 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 + + alias_method_chain :add_reflection, :descendants + + end + end +end -- libgit2 0.21.2