diff options
Diffstat (limited to 'lib/arel/relations')
-rw-r--r-- | lib/arel/relations/join.rb | 4 | ||||
-rw-r--r-- | lib/arel/relations/relation.rb | 13 |
2 files changed, 13 insertions, 4 deletions
diff --git a/lib/arel/relations/join.rb b/lib/arel/relations/join.rb index 5356e57394..c1c3150629 100644 --- a/lib/arel/relations/join.rb +++ b/lib/arel/relations/join.rb @@ -44,10 +44,10 @@ module Arel end def relation_for(attribute) - x = [externalize(relation1), externalize(relation2)].max do |r1, r2| + [externalize(relation1), externalize(relation2)].max do |r1, r2| o1, o2 = r1.relation_for(attribute), r2.relation_for(attribute) a1, a2 = o1 && o1[attribute], o2 && o2[attribute] - + attribute / a1 <=> attribute / a2 end.relation_for(attribute) end diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb index cd58f0f15c..fc47a129a0 100644 --- a/lib/arel/relations/relation.rb +++ b/lib/arel/relations/relation.rb @@ -138,12 +138,21 @@ module Arel def attribute_for_name(name) attributes.detect { |a| a.alias_or_name.to_s == name.to_s } end - + + # TESTME - added relation_for(x)[x] because of AR def attribute_for_attribute(attribute) attributes.select { |a| a =~ attribute }.max do |a1, a2| - (attribute / a1) <=> (attribute / a2) + (attribute / relation_for(a1)[a1]) <=> (attribute / relation_for(a2)[a2]) + end + end + + def attribute_for_attribute_with_memoization(attribute) + @attribute_for_attribute ||= Hash.new do |h, a| + h[a] = attribute_for_attribute_without_memoization(a) end + @attribute_for_attribute[attribute] end + alias_method_chain :attribute_for_attribute, :memoization end include AttributeAccessable |