aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/arel/relations/compound.rb6
-rw-r--r--lib/arel/relations/join.rb14
-rw-r--r--lib/arel/relations/nil.rb3
-rw-r--r--lib/arel/relations/recursion.rb12
-rw-r--r--lib/arel/relations/relation.rb4
5 files changed, 27 insertions, 12 deletions
diff --git a/lib/arel/relations/compound.rb b/lib/arel/relations/compound.rb
index ca192a6e8a..94616ff14f 100644
--- a/lib/arel/relations/compound.rb
+++ b/lib/arel/relations/compound.rb
@@ -2,7 +2,7 @@ module Arel
class Compound < Relation
attr_reader :relation
hash_on :relation
- delegate :joins, :selects, :orders, :groupings, :inserts, :taken,
+ delegate :joins, :selects, :join?, :orders, :groupings, :inserts, :taken,
:skipped, :name, :aggregation?, :column_for,
:engine, :table, :table_sql,
:to => :relation
@@ -10,5 +10,9 @@ module Arel
def attributes
@attributes ||= relation.attributes.collect { |a| a.bind(self) }
end
+
+ def relation_for(attribute)
+ join? && relation.relation_for(attribute) || self[attribute] && 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 d42af5a499..05ed6efc23 100644
--- a/lib/arel/relations/join.rb
+++ b/lib/arel/relations/join.rb
@@ -49,16 +49,18 @@ module Arel
end
end
+ def aggregation?
+ relation1.aggregation? or relation2.aggregation?
+ end
+
+ def join?
+ true
+ end
+
private
# FIXME - make instance method
def externalize(relation)
relation.aggregation?? Aggregation.new(relation) : relation
end
end
-
- class Relation
- def relation_for(attribute)
- self[attribute] && self
- end
- end
end \ No newline at end of file
diff --git a/lib/arel/relations/nil.rb b/lib/arel/relations/nil.rb
index b0d97dd174..34f9ea8722 100644
--- a/lib/arel/relations/nil.rb
+++ b/lib/arel/relations/nil.rb
@@ -1,6 +1,7 @@
module Arel
class Nil < Relation
- def table; self end
+ include Recursion::BaseCase
+
def table_sql(formatter = nil); '' end
def relation_for(attribute); nil end
def name; '' end
diff --git a/lib/arel/relations/recursion.rb b/lib/arel/relations/recursion.rb
index 848b059507..c5ca171fd2 100644
--- a/lib/arel/relations/recursion.rb
+++ b/lib/arel/relations/recursion.rb
@@ -8,6 +8,18 @@ module Arel
def table_sql(formatter = Sql::TableReference.new(self))
formatter.table self
end
+
+ def relation_for(attribute)
+ self[attribute] && self
+ end
+
+ def join?
+ false
+ end
+
+ def aggregation?
+ false
+ end
end
end
end \ No newline at end of file
diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb
index c576033938..884b743f20 100644
--- a/lib/arel/relations/relation.rb
+++ b/lib/arel/relations/relation.rb
@@ -39,10 +39,6 @@ module Arel
@christener ||= Sql::Christener.new
end
- def aggregation?
- false
- end
-
module Enumerable
include ::Enumerable