aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-04 17:03:31 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-05-04 17:03:31 -0700
commit9d8e661a1ad5e2f1904cef1d076355273aa6146e (patch)
treebed578b1c8e677314779fd18fd7fc88eb7bddee7 /lib/arel
parentf413129f37bbbc4100317cb60179f43291e69f8e (diff)
downloadrails-9d8e661a1ad5e2f1904cef1d076355273aa6146e.tar.gz
rails-9d8e661a1ad5e2f1904cef1d076355273aa6146e.tar.bz2
rails-9d8e661a1ad5e2f1904cef1d076355273aa6146e.zip
minor cleanup
Diffstat (limited to 'lib/arel')
-rw-r--r--lib/arel/primitives/attribute.rb55
-rw-r--r--lib/arel/relations/alias.rb5
-rw-r--r--lib/arel/relations/grouping.rb4
-rw-r--r--lib/arel/relations/join.rb7
-rw-r--r--lib/arel/relations/relation.rb11
-rw-r--r--lib/arel/relations/table.rb4
6 files changed, 40 insertions, 46 deletions
diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb
index 9215ea64a0..14b8c18cb2 100644
--- a/lib/arel/primitives/attribute.rb
+++ b/lib/arel/primitives/attribute.rb
@@ -1,13 +1,12 @@
module Arel
class Attribute
attr_reader :relation, :name, :alias, :ancestor
- delegate :engine, :to => :relation
+ delegate :engine, :christener, :to => :relation
def initialize(relation, name, options = {})
@relation, @name, @alias, @ancestor = relation, name, options[:alias], options[:ancestor]
end
- # INVESTIGATE
def alias_or_name
@alias || name
end
@@ -16,6 +15,30 @@ module Arel
false
end
+ def column
+ original_relation.column_for(self)
+ end
+
+ def original_relation
+ relation.relation_for(self)
+ end
+
+ def format(object)
+ object.to_sql(formatter)
+ end
+
+ def to_sql(formatter = Sql::WhereCondition.new(relation))
+ formatter.attribute self
+ end
+
+ def ==(other)
+ self.class == other.class and
+ relation == other.relation and
+ name == other.name and
+ @alias == other.alias and
+ ancestor == other.ancestor
+ end
+
module Transformations
def as(aliaz = nil)
Attribute.new(relation, name, :alias => aliaz, :ancestor => self)
@@ -31,18 +54,6 @@ module Arel
end
include Transformations
- def column
- relation.column_for(self)
- end
-
- def ==(other)
- self.class == other.class and
- relation == other.relation and
- name == other.name and
- @alias == other.alias and
- ancestor == other.ancestor
- end
-
module Congruence
def self.included(klass)
klass.hash_on :name
@@ -117,22 +128,6 @@ module Arel
end
end
include Expressions
-
- def to_sql(formatter = Sql::WhereCondition.new(relation))
- formatter.attribute self
- end
-
- def format(object)
- object.to_sql(formatter)
- end
-
- def original_relation
- relation.relation_for(self)
- end
-
- def christener
- relation.christener
- end
private
def formatter
diff --git a/lib/arel/relations/alias.rb b/lib/arel/relations/alias.rb
index b4e8965625..0099a794b4 100644
--- a/lib/arel/relations/alias.rb
+++ b/lib/arel/relations/alias.rb
@@ -15,5 +15,10 @@ module Arel
def relation_for(attribute)
self[attribute] and self
end
+
+ def table_sql(formatter = Sql::TableReference.new(self))
+ formatter.table self
+ end
+
end
end \ No newline at end of file
diff --git a/lib/arel/relations/grouping.rb b/lib/arel/relations/grouping.rb
index e3686f7f28..3f0ea54407 100644
--- a/lib/arel/relations/grouping.rb
+++ b/lib/arel/relations/grouping.rb
@@ -16,10 +16,6 @@ module Arel
true
end
- def table_sql(formatter = Sql::TableReference.new(self))
- to_sql(formatter)
- end
-
def name
table.name + '_aggregation'
end
diff --git a/lib/arel/relations/join.rb b/lib/arel/relations/join.rb
index 20c19e0848..1b37b3f225 100644
--- a/lib/arel/relations/join.rb
+++ b/lib/arel/relations/join.rb
@@ -23,11 +23,6 @@ module Arel
externalize(relation2).attributes).collect { |a| a.bind(self) }
end
- # TESTME: Not sure which scenario needs this method, was driven by failing tests in ActiveRecord
- def column_for(attribute)
- (relation1[attribute] || relation2[attribute]).column
- end
-
def joins(formatter = Sql::TableReference.new(self))
this_join = [
join_sql,
@@ -58,7 +53,7 @@ module Arel
def table
relation1.aggregation?? relation1 : relation1.table
end
-
+
delegate :name, :to => :relation1
def relation_for(attribute)
diff --git a/lib/arel/relations/relation.rb b/lib/arel/relations/relation.rb
index e08123eaf5..62656773dd 100644
--- a/lib/arel/relations/relation.rb
+++ b/lib/arel/relations/relation.rb
@@ -104,8 +104,8 @@ module Arel
relation.name
end
- def table_sql(formatter = Sql::TableReference.new(self))
- formatter.table self
+ def table
+ self
end
end
include Externalizable
@@ -113,7 +113,7 @@ module Arel
def to_sql(formatter = Sql::SelectStatement.new(self))
formatter.select [
"SELECT #{attributes.collect { |a| a.to_sql(Sql::SelectClause.new(self)) }.join(', ')}",
- "FROM #{thing}",
+ "FROM #{table_sql(Sql::TableReference.new(self))}",
(joins(Sql::TableReference.new(self)) unless joins.blank? ),
("WHERE #{selects.collect { |s| s.to_sql(Sql::WhereClause.new(self)) }.join("\n\tAND ")}" unless selects.blank? ),
("ORDER BY #{orders.collect { |o| o.to_sql(Sql::OrderClause.new(self)) }.join(', ')}" unless orders.blank? ),
@@ -123,9 +123,8 @@ module Arel
].compact.join("\n"), name
end
alias_method :to_s, :to_sql
-
- # FIXME
- def thing
+
+ def table_sql(formatter = Sql::TableReference.new(self))
if table.aggregation?
table.to_sql(Sql::TableReference.new(self))
else
diff --git a/lib/arel/relations/table.rb b/lib/arel/relations/table.rb
index fcde94b595..75593731e0 100644
--- a/lib/arel/relations/table.rb
+++ b/lib/arel/relations/table.rb
@@ -27,6 +27,10 @@ module Arel
self[attribute] and self
end
+ def table_sql(formatter = Sql::TableReference.new(self))
+ formatter.table self
+ end
+
def ==(other)
self.class == other.class and
name == other.name