diff options
Diffstat (limited to 'lib/arel/relations')
-rw-r--r-- | lib/arel/relations/aggregation.rb | 2 | ||||
-rw-r--r-- | lib/arel/relations/alias.rb | 5 | ||||
-rw-r--r-- | lib/arel/relations/compound.rb | 2 | ||||
-rw-r--r-- | lib/arel/relations/join.rb | 8 | ||||
-rw-r--r-- | lib/arel/relations/projection.rb | 2 | ||||
-rw-r--r-- | lib/arel/relations/recursion.rb | 2 | ||||
-rw-r--r-- | lib/arel/relations/relation.rb | 10 |
7 files changed, 11 insertions, 20 deletions
diff --git a/lib/arel/relations/aggregation.rb b/lib/arel/relations/aggregation.rb index 7a56834125..955a71c0b0 100644 --- a/lib/arel/relations/aggregation.rb +++ b/lib/arel/relations/aggregation.rb @@ -16,6 +16,6 @@ Aggregation = Struct.new(:relation) do end def attributes - relation.attributes.collect(&:to_attribute) + @attributes ||= relation.attributes.collect(&:to_attribute) end end
\ No newline at end of file diff --git a/lib/arel/relations/alias.rb b/lib/arel/relations/alias.rb index 08be02e862..d14a51f67a 100644 --- a/lib/arel/relations/alias.rb +++ b/lib/arel/relations/alias.rb @@ -1,13 +1,10 @@ module Arel class Alias < Compound include Recursion::BaseCase + alias_method :==, :equal? def initialize(relation) @relation = relation end - - def ==(other) - equal? other - end end end
\ No newline at end of file diff --git a/lib/arel/relations/compound.rb b/lib/arel/relations/compound.rb index 663711760c..649d11e8b1 100644 --- a/lib/arel/relations/compound.rb +++ b/lib/arel/relations/compound.rb @@ -3,7 +3,7 @@ module Arel attr_reader :relation hash_on :relation delegate :joins, :selects, :orders, :groupings, :inserts, :taken, - :skipped, :name, :alias, :aggregation?, :column_for, + :skipped, :name, :aggregation?, :column_for, :engine, :table, :relation_for, :table_sql, :to => :relation diff --git a/lib/arel/relations/join.rb b/lib/arel/relations/join.rb index b3452968e4..b7c5c3f39b 100644 --- a/lib/arel/relations/join.rb +++ b/lib/arel/relations/join.rb @@ -27,7 +27,7 @@ module Arel end def attributes - (externalize(relation1).attributes + + @attributes ||= (externalize(relation1).attributes + externalize(relation2).attributes).collect { |a| a.bind(self) } end @@ -44,9 +44,11 @@ module Arel end def relation_for(attribute) - [externalize(relation1).relation_for(attribute), externalize(relation2).relation_for(attribute)].max do |r1, r2| + [ + externalize(relation1).relation_for(attribute), + externalize(relation2).relation_for(attribute) + ].max do |r1, r2| a1, a2 = r1 && r1[attribute], r2 && r2[attribute] - attribute / a1 <=> attribute / a2 end end diff --git a/lib/arel/relations/projection.rb b/lib/arel/relations/projection.rb index f09d4f894b..8a08cda70c 100644 --- a/lib/arel/relations/projection.rb +++ b/lib/arel/relations/projection.rb @@ -7,7 +7,7 @@ module Arel end def attributes - projections.collect { |p| p.bind(self) } + @attributes ||= projections.collect { |p| p.bind(self) } end def ==(other) diff --git a/lib/arel/relations/recursion.rb b/lib/arel/relations/recursion.rb index 90976c702b..2c6024dc30 100644 --- a/lib/arel/relations/recursion.rb +++ b/lib/arel/relations/recursion.rb @@ -6,7 +6,7 @@ module Arel end def relation_for(attribute) - self + self[attribute] and self end def table_sql(formatter = Sql::TableReference.new(self)) diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb index db7d746c79..c576033938 100644 --- a/lib/arel/relations/relation.rb +++ b/lib/arel/relations/relation.rb @@ -139,20 +139,12 @@ module Arel attributes.detect { |a| a.named?(name) } end - # TESTME - added relation_for(x)[x] because of AR + # TESTME - added original_attribute because of AR def find_attribute_matching_attribute(attribute) attributes.select { |a| a.match?(attribute) }.max do |a1, a2| (attribute / a1.original_attribute) <=> (attribute / a2.original_attribute) end end - - def find_attribute_matching_attribute_with_memoization(attribute) - @attribute_for_attribute ||= Hash.new do |h, a| - h[a] = find_attribute_matching_attribute_without_memoization(a) - end - @attribute_for_attribute[attribute] - end - alias_method_chain :find_attribute_matching_attribute, :memoization end include AttributeAccessable |