diff options
Diffstat (limited to 'lib/arel/primitives')
-rw-r--r-- | lib/arel/primitives/attribute.rb | 4 | ||||
-rw-r--r-- | lib/arel/primitives/value.rb | 6 |
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) |