aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/relations.rb1
-rw-r--r--lib/arel/relations/aggregation.rb21
-rw-r--r--lib/arel/relations/compound.rb2
-rw-r--r--lib/arel/relations/join.rb24
-rw-r--r--lib/arel/relations/relation.rb5
5 files changed, 24 insertions, 29 deletions
diff --git a/lib/arel/relations.rb b/lib/arel/relations.rb
index 6cd599ad5d..1a216993e0 100644
--- a/lib/arel/relations.rb
+++ b/lib/arel/relations.rb
@@ -4,6 +4,7 @@ require 'arel/relations/nil'
require 'arel/relations/compound'
require 'arel/relations/writing'
require 'arel/relations/table'
+require 'arel/relations/aggregation'
require 'arel/relations/join'
require 'arel/relations/grouping'
require 'arel/relations/projection'
diff --git a/lib/arel/relations/aggregation.rb b/lib/arel/relations/aggregation.rb
new file mode 100644
index 0000000000..7a56834125
--- /dev/null
+++ b/lib/arel/relations/aggregation.rb
@@ -0,0 +1,21 @@
+Aggregation = Struct.new(:relation) do
+ def selects
+ []
+ end
+
+ def table
+ relation
+ end
+
+ def relation_for(attribute)
+ relation
+ end
+
+ def table_sql(formatter = Sql::TableReference.new(relation))
+ relation.to_sql(formatter)
+ end
+
+ def attributes
+ relation.attributes.collect(&:to_attribute)
+ end
+end \ No newline at end of file
diff --git a/lib/arel/relations/compound.rb b/lib/arel/relations/compound.rb
index f0a3392e09..7b6f3a46f8 100644
--- a/lib/arel/relations/compound.rb
+++ b/lib/arel/relations/compound.rb
@@ -4,7 +4,7 @@ module Arel
hash_on :relation
delegate :joins, :selects, :orders, :groupings, :inserts, :taken,
:skipped, :name, :alias, :aggregation?, :column_for,
- :engine, :name_for, :table, :relation_for, :table_sql,
+ :engine, :table, :relation_for, :table_sql,
:to => :relation
def attributes
diff --git a/lib/arel/relations/join.rb b/lib/arel/relations/join.rb
index 01e7e36f37..4269731092 100644
--- a/lib/arel/relations/join.rb
+++ b/lib/arel/relations/join.rb
@@ -51,29 +51,7 @@ module Arel
private
def externalize(relation)
- Externalizer.new(relation)
- end
-
- Externalizer = Struct.new(:relation) do
- def selects
- relation.aggregation?? [] : relation.selects
- end
-
- def table
- relation.aggregation?? relation : relation.table
- end
-
- def relation_for(attribute)
- relation.aggregation?? relation : relation.relation_for(attribute)
- end
-
- def table_sql(formatter = Sql::TableReference.new(relation))
- relation.aggregation?? relation.to_sql(formatter) : relation.table.table_sql(formatter)
- end
-
- def attributes
- relation.aggregation?? relation.attributes.collect(&:to_attribute) : relation.attributes
- end
+ relation.aggregation?? Aggregation.new(relation) : relation
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb
index 14d2143a8b..cc0f40ea17 100644
--- a/lib/arel/relations/relation.rb
+++ b/lib/arel/relations/relation.rb
@@ -4,11 +4,6 @@ module Arel
Session.new
end
- # INVESTIGATE
- def name_for(relation)
- relation.name
- end
-
def to_sql(formatter = Sql::SelectStatement.new(self))
formatter.select [
"SELECT #{attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) }.join(', ')}",