aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/relations
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-17 23:03:56 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-17 23:03:56 -0700
commit6e1450a2a646e416aaea003eff19b7703c563bed (patch)
tree5caa324b2d33d1b48d7e440bf36fc9fe8efa5405 /lib/arel/relations
parent724a2684139342eb4613f78bfae723ef00911ff7 (diff)
downloadrails-6e1450a2a646e416aaea003eff19b7703c563bed.tar.gz
rails-6e1450a2a646e416aaea003eff19b7703c563bed.tar.bz2
rails-6e1450a2a646e416aaea003eff19b7703c563bed.zip
performance enhancements
Diffstat (limited to 'lib/arel/relations')
-rw-r--r--lib/arel/relations/aggregation.rb2
-rw-r--r--lib/arel/relations/compound.rb6
-rw-r--r--lib/arel/relations/join.rb28
-rw-r--r--lib/arel/relations/nil.rb1
-rw-r--r--lib/arel/relations/recursion.rb4
5 files changed, 15 insertions, 26 deletions
diff --git a/lib/arel/relations/aggregation.rb b/lib/arel/relations/aggregation.rb
index d409c34284..a6f40be786 100644
--- a/lib/arel/relations/aggregation.rb
+++ b/lib/arel/relations/aggregation.rb
@@ -15,7 +15,7 @@ module Arel
end
def attributes
- @attributes ||= relation.attributes.collect(&:to_attribute)
+ @attributes ||= relation.attributes.collect(&:to_attribute).collect { |a| a.bind(self) }
end
def ==(other)
diff --git a/lib/arel/relations/compound.rb b/lib/arel/relations/compound.rb
index abc5838805..9921568157 100644
--- a/lib/arel/relations/compound.rb
+++ b/lib/arel/relations/compound.rb
@@ -10,9 +10,9 @@ module Arel
def attributes
@attributes ||= relation.attributes.collect { |a| a.bind(self) }
end
-
- def relation_for(attribute)
- join? && relation.relation_for(attribute) || has_attribute?(attribute) && self
+
+ def selects
+ @selects || relation.selects.collect { |s| s.bind(self) }
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/join.rb b/lib/arel/relations/join.rb
index abd4eae4f6..9cc9f95c81 100644
--- a/lib/arel/relations/join.rb
+++ b/lib/arel/relations/join.rb
@@ -7,14 +7,6 @@ module Arel
def initialize(join_sql, relation1, relation2 = Nil.new, *predicates)
@join_sql, @relation1, @relation2, @predicates = join_sql, relation1, relation2, predicates
end
-
- def ==(other)
- Join == other.class and
- predicates == other.predicates and (
- (relation1 == other.relation1 and relation2 == other.relation2) or
- (relation2 == other.relation1 and relation1 == other.relation2)
- )
- end
def table_sql(formatter = Sql::TableReference.new(self))
relation1.externalize.table_sql(formatter)
@@ -25,7 +17,7 @@ module Arel
join_sql,
relation2.externalize.table_sql(formatter),
("ON" unless predicates.blank?),
- (predicates + relation2.externalize.selects).collect { |p| p.bind(environment).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ')
+ (ons + relation2.externalize.selects).collect { |p| p.bind(environment).to_sql(Sql::WhereClause.new(environment)) }.join(' AND ')
].compact.join(" ")
[relation1.joins(environment), this_join, relation2.joins(environment)].compact.join(" ")
end
@@ -39,14 +31,8 @@ module Arel
relation1.externalize.selects
end
- def relation_for(attribute)
- [
- relation1.externalize.relation_for(attribute),
- relation2.externalize.relation_for(attribute)
- ].max do |r1, r2|
- a1, a2 = r1 && r1[attribute], r2 && r2[attribute]
- attribute / a1 <=> attribute / a2
- end
+ def ons
+ @ons ||= @predicates.collect { |p| p.bind(self) }
end
# TESTME
@@ -57,6 +43,14 @@ module Arel
def join?
true
end
+
+ def ==(other)
+ Join == other.class and
+ predicates == other.predicates and (
+ (relation1 == other.relation1 and relation2 == other.relation2) or
+ (relation2 == other.relation1 and relation1 == other.relation2)
+ )
+ end
end
class Relation
diff --git a/lib/arel/relations/nil.rb b/lib/arel/relations/nil.rb
index e8d4cbc481..c34fe71473 100644
--- a/lib/arel/relations/nil.rb
+++ b/lib/arel/relations/nil.rb
@@ -1,7 +1,6 @@
module Arel
class Nil < Relation
def table_sql(formatter = nil); '' end
- def relation_for(attribute); nil end
def name; '' end
def ==(other)
diff --git a/lib/arel/relations/recursion.rb b/lib/arel/relations/recursion.rb
index c2fcf1bd21..848b059507 100644
--- a/lib/arel/relations/recursion.rb
+++ b/lib/arel/relations/recursion.rb
@@ -8,10 +8,6 @@ module Arel
def table_sql(formatter = Sql::TableReference.new(self))
formatter.table self
end
-
- def relation_for(attribute)
- has_attribute?(attribute) && self
- end
end
end
end \ No newline at end of file