aboutsummaryrefslogtreecommitdiffstats
path: root/lib/arel/primitives
diff options
context:
space:
mode:
authorEmilio Tagua <miloops@gmail.com>2009-04-29 19:38:39 -0300
committerEmilio Tagua <miloops@gmail.com>2009-04-29 19:38:39 -0300
commitb4b73d9520a2ff27021b530ccd3dcd96973ce5fe (patch)
tree5a72648ea38f5ca0d739119d54617596d3e2b139 /lib/arel/primitives
parent5e4bfb1ce4144785feaeffc6210740e3e4ce5770 (diff)
downloadrails-b4b73d9520a2ff27021b530ccd3dcd96973ce5fe.tar.gz
rails-b4b73d9520a2ff27021b530ccd3dcd96973ce5fe.tar.bz2
rails-b4b73d9520a2ff27021b530ccd3dcd96973ce5fe.zip
Added DISTINCT support. Modified when to quote or not columns and tables.
Diffstat (limited to 'lib/arel/primitives')
-rw-r--r--lib/arel/primitives/attribute.rb4
-rw-r--r--lib/arel/primitives/value.rb6
2 files changed, 7 insertions, 3 deletions
diff --git a/lib/arel/primitives/attribute.rb b/lib/arel/primitives/attribute.rb
index 7021e9f9ed..6cb558d8ce 100644
--- a/lib/arel/primitives/attribute.rb
+++ b/lib/arel/primitives/attribute.rb
@@ -120,8 +120,8 @@ module Arel
include Predications
module Expressions
- def count
- Expression.new(self, "COUNT")
+ def count(distinct = false)
+ distinct ? Expression.new(self, "DISTINCT").count : Expression.new(self, "COUNT")
end
def sum
diff --git a/lib/arel/primitives/value.rb b/lib/arel/primitives/value.rb
index 36a7fb7c71..9c6e518a95 100644
--- a/lib/arel/primitives/value.rb
+++ b/lib/arel/primitives/value.rb
@@ -6,7 +6,11 @@ module Arel
def to_sql(formatter = Sql::WhereCondition.new(relation))
- formatter.value value
+ if value =~ /^\(.*\)$/
+ value
+ else
+ formatter.value value
+ end
end
def format(object)