diff options
author | Yasuo Honda <yasuo.honda@gmail.com> | 2013-06-06 21:33:20 +0900 |
---|---|---|
committer | Yasuo Honda <yasuo.honda@gmail.com> | 2013-10-14 11:15:35 +0900 |
commit | 51f5bece0867316d035d5d8eeb3a2eb44cf89ad1 (patch) | |
tree | 71ed864b2ba07dcbe6bb974f4ff8d70420bbd587 | |
parent | bd6adc877af4687aec636f08e96e19785eea209d (diff) | |
download | rails-51f5bece0867316d035d5d8eeb3a2eb44cf89ad1.tar.gz rails-51f5bece0867316d035d5d8eeb3a2eb44cf89ad1.tar.bz2 rails-51f5bece0867316d035d5d8eeb3a2eb44cf89ad1.zip |
Support `columns_for_distinct`
-rw-r--r-- | lib/arel/visitors/oracle.rb | 4 | ||||
-rw-r--r-- | test/visitors/test_oracle.rb | 3 |
2 files changed, 4 insertions, 3 deletions
diff --git a/lib/arel/visitors/oracle.rb b/lib/arel/visitors/oracle.rb index b58d7338ef..b6f7b4cc3c 100644 --- a/lib/arel/visitors/oracle.rb +++ b/lib/arel/visitors/oracle.rb @@ -8,7 +8,7 @@ module Arel # if need to select first records without ORDER BY and GROUP BY and without DISTINCT # then can use simple ROWNUM in WHERE clause - if o.limit && o.orders.empty? && !o.offset && o.cores.first.projections.first !~ /^DISTINCT / + if o.limit && o.orders.empty? && !o.offset && o.cores.first.set_quantifier.class.to_s !~ /Distinct/ o.cores.last.wheres.push Nodes::LessThanOrEqual.new( Nodes::SqlLiteral.new('ROWNUM'), o.limit.expr ) @@ -83,7 +83,7 @@ module Arel return o if o.orders.empty? return o unless o.cores.any? do |core| core.projections.any? do |projection| - /DISTINCT.*FIRST_VALUE/ === projection + /FIRST_VALUE/ === projection end end # Previous version with join and split broke ORDER BY clause diff --git a/test/visitors/test_oracle.rb b/test/visitors/test_oracle.rb index 421e9951e6..bd22822bca 100644 --- a/test/visitors/test_oracle.rb +++ b/test/visitors/test_oracle.rb @@ -85,7 +85,8 @@ module Arel it 'creates a subquery when there is DISTINCT' do stmt = Nodes::SelectStatement.new - stmt.cores.first.projections << Nodes::SqlLiteral.new('DISTINCT id') + stmt.cores.first.set_quantifier = Arel::Nodes::Distinct.new + stmt.cores.first.projections << Nodes::SqlLiteral.new('id') stmt.limit = Arel::Nodes::Limit.new(10) sql = @visitor.accept stmt sql.must_be_like %{ |