diff options
-rw-r--r-- | Rakefile | 2 | ||||
-rw-r--r-- | lib/arel/visitors/to_sql.rb | 1 | ||||
-rw-r--r-- | test/test_select_manager.rb | 14 |
3 files changed, 15 insertions, 2 deletions
@@ -15,6 +15,4 @@ Hoe.spec 'arel' do self.readme_file = 'README.markdown' self.extra_rdoc_files = FileList['README.markdown'] - self.extra_dev_deps << [ 'hoe', '>= 2.1.0' ] - self.extra_dev_deps << [ 'minitest', '>= 1.6.0' ] end diff --git a/lib/arel/visitors/to_sql.rb b/lib/arel/visitors/to_sql.rb index 1550757cf4..1c91d7f5e6 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 |