diff options
author | Hugo Peixoto <hugo.peixoto@gmail.com> | 2011-03-06 10:28:46 +0000 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-03-21 14:52:55 -0700 |
commit | 856fd75c9b6defb7711f93e6ecda2932e98c4113 (patch) | |
tree | ca47e76e39a6ae135793136e00bfda3f304efe8c | |
parent | d13ae3d51b32bfda31ebfee5230122f8fdb3a343 (diff) | |
download | rails-856fd75c9b6defb7711f93e6ecda2932e98c4113.tar.gz rails-856fd75c9b6defb7711f93e6ecda2932e98c4113.tar.bz2 rails-856fd75c9b6defb7711f93e6ecda2932e98c4113.zip |
Fixes rails bug #6058.
Propagates 'where' clauses when subquerying is triggered on the UpdateManager.
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 1 | ||||
-rw-r--r-- | test/test_select_manager.rb | 14 |
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index f30557e509..6bf5a3bb6b 100644 --- a/lib/arel/visitors/to_sql.rb +++ b/lib/arel/visitors/to_sql.rb @@ -35,6 +35,7 @@ module Arel stmt = Nodes::SelectStatement.new core = stmt.cores.first core.froms = o.relation + core.wheres = o.wheres core.projections = [key] stmt.limit = o.limit stmt.orders = o.orders diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index 2fe43aa982..410fe38e2a 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -713,6 +713,20 @@ module Arel } end + it 'copies where clauses when nesting is triggered' do + engine = EngineProxy.new Table.engine + table = Table.new :users + manager = Arel::SelectManager.new engine + manager.where table[:foo].eq 10 + manager.take 42 + manager.from table + stmt = manager.compile_update(table[:id] => 1) + + stmt.to_sql.must_be_like %{ + UPDATE "users" SET "id" = 1 WHERE "users"."id" IN (SELECT "users"."id" FROM "users" WHERE "users"."foo" = 10 LIMIT 42) + } + end + it 'executes an update statement' do engine = EngineProxy.new Table.engine table = Table.new :users |