Skip to content

Commit

Permalink
Fixes rails bug #6058.
Browse files Browse the repository at this point in the history
Propagates 'where' clauses when subquerying is triggered on the UpdateManager.
  • Loading branch information
hugopeixoto authored and tenderlove committed Mar 21, 2011
1 parent d13ae3d commit 856fd75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/arel/visitors/to_sql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def build_subselect key, o
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
Expand Down
14 changes: 14 additions & 0 deletions test/test_select_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,20 @@ def test_join_sources
}
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
Expand Down

0 comments on commit 856fd75

Please sign in to comment.