Commit c9c81cfa67b812a4624765f22b28b6c1b88a2aa5
1 parent
1b6f9e37
Exists in
master
and in
20 other branches
rails4: apply associations extensions to child classes
Showing
2 changed files
with
22 additions
and
0 deletions
Show diff stats
lib/noosfero/core_ext.rb
@@ -0,0 +1,20 @@ | @@ -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 |