diff --git a/History.txt b/History.txt index e794edb132..ddfced9666 100644 --- a/History.txt +++ b/History.txt @@ -9,6 +9,9 @@ * Calls to `insert` are deprecated. Please use `compile_insert` then call `to_sql` on the resulting object and execute that SQL. + * Calls to `update` are deprecated. Please use `compile_update` then call + `to_sql` on the resulting object and execute that SQL. + == 2.0.6 12/01/2010 * Bug Fixes diff --git a/lib/arel/crud.rb b/lib/arel/crud.rb index 8de008c09e..06883d9ac6 100644 --- a/lib/arel/crud.rb +++ b/lib/arel/crud.rb @@ -2,8 +2,7 @@ module Arel ### # FIXME hopefully we can remove this module Crud - # FIXME: this method should go away - def update values + def compile_update values um = UpdateManager.new @engine if Nodes::SqlLiteral === values @@ -16,7 +15,19 @@ module Arel um.take @ast.limit um.order(*@ast.orders) um.wheres = @ctx.wheres + um + end + # FIXME: this method should go away + def update values + if $VERBOSE + warn <<-eowarn +update (#{caller.first}) is deprecated and will be removed in ARel 2.2.0. Please +switch to `compile_update` + eowarn + end + + um = compile_update values @engine.connection.update um.to_sql, 'AREL' end diff --git a/test/test_crud.rb b/test/test_crud.rb index 582f0ec072..0a727bce0a 100644 --- a/test/test_crud.rb +++ b/test/test_crud.rb @@ -47,10 +47,8 @@ module Arel table = Table.new :users fc = FakeCrudder.new fc.from table - fc.update [[table[:id], 'foo']] - fc.engine.calls.find { |method, _| - method == :update - }.wont_be_nil + stmt = fc.compile_update [[table[:id], 'foo']] + assert_instance_of Arel::UpdateManager, stmt end end diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb index d63bec0093..ee4341c1ce 100644 --- a/test/test_select_manager.rb +++ b/test/test_select_manager.rb @@ -312,7 +312,6 @@ module Arel manager.join_sql.must_be_like %{ INNER JOIN "users" "users_2" "users"."id" = "users_2"."id" } - manager.joins(manager).must_equal manager.join_sql end it 'returns outer join sql' do @@ -323,7 +322,6 @@ module Arel manager.join_sql.must_be_like %{ LEFT OUTER JOIN "users" "users_2" "users"."id" = "users_2"."id" } - manager.joins(manager).must_equal manager.join_sql end it 'returns string join sql' do @@ -331,7 +329,6 @@ module Arel manager = Arel::SelectManager.new Table.engine manager.from Nodes::StringJoin.new(table, 'hello') manager.join_sql.must_be_like %{ 'hello' } - manager.joins(manager).must_equal manager.join_sql end it 'returns nil join sql' do @@ -436,9 +433,9 @@ module Arel manager = Arel::SelectManager.new engine manager.from table manager.take 1 - manager.update(SqlLiteral.new('foo = bar')) + stmt = manager.compile_update(SqlLiteral.new('foo = bar')) - engine.executed.last.must_be_like %{ + stmt.to_sql.must_be_like %{ UPDATE "users" SET foo = bar WHERE "users"."id" IN (SELECT "users"."id" FROM "users" LIMIT 1) } @@ -450,9 +447,9 @@ module Arel manager = Arel::SelectManager.new engine manager.from table manager.order :foo - manager.update(SqlLiteral.new('foo = bar')) + stmt = manager.compile_update(SqlLiteral.new('foo = bar')) - engine.executed.last.must_be_like %{ + stmt.to_sql.must_be_like %{ UPDATE "users" SET foo = bar WHERE "users"."id" IN (SELECT "users"."id" FROM "users" ORDER BY foo) } @@ -463,9 +460,9 @@ module Arel table = Table.new :users manager = Arel::SelectManager.new engine manager.from table - manager.update(SqlLiteral.new('foo = bar')) + stmt = manager.compile_update(SqlLiteral.new('foo = bar')) - engine.executed.last.must_be_like %{ UPDATE "users" SET foo = bar } + stmt.to_sql.must_be_like %{ UPDATE "users" SET foo = bar } end it 'copies where clauses' do @@ -474,9 +471,9 @@ module Arel manager = Arel::SelectManager.new engine manager.where table[:id].eq 10 manager.from table - manager.update(table[:id] => 1) + stmt = manager.compile_update(table[:id] => 1) - engine.executed.last.must_be_like %{ + stmt.to_sql.must_be_like %{ UPDATE "users" SET "id" = 1 WHERE "users"."id" = 10 } end @@ -486,9 +483,9 @@ module Arel table = Table.new :users manager = Arel::SelectManager.new engine manager.from table - manager.update(table[:id] => 1) + stmt = manager.compile_update(table[:id] => 1) - engine.executed.last.must_be_like %{ + stmt.to_sql.must_be_like %{ UPDATE "users" SET "id" = 1 } end diff --git a/test/test_table.rb b/test/test_table.rb index b9998174a1..93cdde8f68 100644 --- a/test/test_table.rb +++ b/test/test_table.rb @@ -48,12 +48,6 @@ module Arel end describe 'backwards compat' do - describe 'joins' do - it 'returns nil' do - @relation.joins(nil).must_equal nil - end - end - describe 'join' do it 'noops on nil' do mgr = @relation.join nil