aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2008-03-16 17:27:40 -0700
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2008-03-16 17:27:40 -0700
commit7bd0d634867ccbdf4537ba3d62b865b1cb7beebf (patch)
treef469465c385a99722b2263cae5f68a1a961a3c76 /lib
parentaa5c9a19826c84bbb9c9f75f8d1a4b04b874780c (diff)
downloadrails-7bd0d634867ccbdf4537ba3d62b865b1cb7beebf.tar.gz
rails-7bd0d634867ccbdf4537ba3d62b865b1cb7beebf.tar.bz2
rails-7bd0d634867ccbdf4537ba3d62b865b1cb7beebf.zip
allowing string passthrough for order clauses
Diffstat (limited to 'lib')
-rw-r--r--lib/active_relation/primitives/attribute.rb14
-rw-r--r--lib/active_relation/relations/relation.rb12
-rw-r--r--lib/active_relation/sql.rb11
3 files changed, 23 insertions, 14 deletions
diff --git a/lib/active_relation/primitives/attribute.rb b/lib/active_relation/primitives/attribute.rb
index ddf5ef5e07..d78e940ffc 100644
--- a/lib/active_relation/primitives/attribute.rb
+++ b/lib/active_relation/primitives/attribute.rb
@@ -63,31 +63,31 @@ module ActiveRelation
module Predications
def eq(other)
- Equality.new(self, other)
+ Equality.new(self, other.bind(relation))
end
def lt(other)
- LessThan.new(self, other)
+ LessThan.new(self, other.bind(relation))
end
def lteq(other)
- LessThanOrEqualTo.new(self, other)
+ LessThanOrEqualTo.new(self, other.bind(relation))
end
def gt(other)
- GreaterThan.new(self, other)
+ GreaterThan.new(self, other.bind(relation))
end
def gteq(other)
- GreaterThanOrEqualTo.new(self, other)
+ GreaterThanOrEqualTo.new(self, other.bind(relation))
end
def matches(regexp)
- Match.new(self, regexp)
+ Match.new(self, regexp.bind(relation))
end
def in(array)
- In.new(self, array)
+ In.new(self, array.bind(relation))
end
end
include Predications
diff --git a/lib/active_relation/relations/relation.rb b/lib/active_relation/relations/relation.rb
index 1364911f0c..fa66bd039b 100644
--- a/lib/active_relation/relations/relation.rb
+++ b/lib/active_relation/relations/relation.rb
@@ -105,12 +105,12 @@ module ActiveRelation
formatter.select [
"SELECT #{attributes.collect { |a| a.to_sql(Sql::SelectExpression.new(engine)) }.join(', ')}",
"FROM #{table_sql}",
- (joins unless joins.blank? ),
- ("WHERE #{selects.collect {|s| s.to_sql(Sql::WhereClause.new(engine))}.join("\n\tAND ")}" unless selects.blank? ),
- ("ORDER BY #{orders.collect(&:to_sql)}" unless orders.blank? ),
- ("GROUP BY #{groupings.collect(&:to_sql)}" unless groupings.blank? ),
- ("LIMIT #{limit}" unless limit.blank? ),
- ("OFFSET #{offset}" unless offset.blank? )
+ (joins unless joins.blank? ),
+ ("WHERE #{selects.collect { |s| s.to_sql(Sql::WhereClause.new(engine)) }.join("\n\tAND ")}" unless selects.blank? ),
+ ("ORDER BY #{orders.collect { |o| o.to_sql(Sql::OrderClause.new(engine)) }.join(', ')}" unless orders.blank? ),
+ ("GROUP BY #{groupings.collect(&:to_sql)}" unless groupings.blank? ),
+ ("LIMIT #{limit}" unless limit.blank? ),
+ ("OFFSET #{offset}" unless offset.blank? )
].compact.join("\n"), self.alias
end
alias_method :to_s, :to_sql
diff --git a/lib/active_relation/sql.rb b/lib/active_relation/sql.rb
index 027356d4d7..3a773fdf6e 100644
--- a/lib/active_relation/sql.rb
+++ b/lib/active_relation/sql.rb
@@ -24,12 +24,21 @@ module ActiveRelation
end
end
- class WhereClause < Formatter
+ class PassThrough < Formatter
def value(value)
value
end
end
+ class WhereClause < PassThrough
+ end
+
+ class OrderClause < PassThrough
+ def attribute(relation_name, attribute_name, aliaz)
+ "#{quote_table_name(relation_name)}.#{quote_column_name(attribute_name)}"
+ end
+ end
+
class WhereCondition < Formatter
def attribute(relation_name, attribute_name, aliaz)
"#{quote_table_name(relation_name)}.#{quote_column_name(attribute_name)}"