Commit c9c81cfa67b812a4624765f22b28b6c1b88a2aa5

Authored by Braulio Bhavamitra
1 parent 1b6f9e37

rails4: apply associations extensions to child classes

lib/noosfero/core_ext.rb
1 1 require 'noosfero/core_ext/string'
2 2 require 'noosfero/core_ext/integer'
3 3 require 'noosfero/core_ext/active_record'
  4 +require 'noosfero/core_ext/active_record/reflection'
  5 +
... ...
lib/noosfero/core_ext/active_record/reflection.rb 0 → 100644
... ... @@ -0,0 +1,20 @@
  1 +
  2 +# on STI classes tike Article and Profile, plugins' extensions
  3 +# on associations should be reflected on descendants
  4 +module ActiveRecord
  5 + 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
  14 + end
  15 +
  16 + alias_method_chain :add_reflection, :descendants
  17 +
  18 + end
  19 + end
  20 +end
... ...