mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
deprecating the update method in favor of compile_update
This commit is contained in:
parent
baa660f62b
commit
a8521641d5
5 changed files with 28 additions and 25 deletions
|
@ -9,6 +9,9 @@
|
||||||
* Calls to `insert` are deprecated. Please use `compile_insert` then call
|
* Calls to `insert` are deprecated. Please use `compile_insert` then call
|
||||||
`to_sql` on the resulting object and execute that SQL.
|
`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
|
== 2.0.6 12/01/2010
|
||||||
|
|
||||||
* Bug Fixes
|
* Bug Fixes
|
||||||
|
|
|
@ -2,8 +2,7 @@ module Arel
|
||||||
###
|
###
|
||||||
# FIXME hopefully we can remove this
|
# FIXME hopefully we can remove this
|
||||||
module Crud
|
module Crud
|
||||||
# FIXME: this method should go away
|
def compile_update values
|
||||||
def update values
|
|
||||||
um = UpdateManager.new @engine
|
um = UpdateManager.new @engine
|
||||||
|
|
||||||
if Nodes::SqlLiteral === values
|
if Nodes::SqlLiteral === values
|
||||||
|
@ -16,7 +15,19 @@ module Arel
|
||||||
um.take @ast.limit
|
um.take @ast.limit
|
||||||
um.order(*@ast.orders)
|
um.order(*@ast.orders)
|
||||||
um.wheres = @ctx.wheres
|
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'
|
@engine.connection.update um.to_sql, 'AREL'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -47,10 +47,8 @@ module Arel
|
||||||
table = Table.new :users
|
table = Table.new :users
|
||||||
fc = FakeCrudder.new
|
fc = FakeCrudder.new
|
||||||
fc.from table
|
fc.from table
|
||||||
fc.update [[table[:id], 'foo']]
|
stmt = fc.compile_update [[table[:id], 'foo']]
|
||||||
fc.engine.calls.find { |method, _|
|
assert_instance_of Arel::UpdateManager, stmt
|
||||||
method == :update
|
|
||||||
}.wont_be_nil
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -312,7 +312,6 @@ module Arel
|
||||||
manager.join_sql.must_be_like %{
|
manager.join_sql.must_be_like %{
|
||||||
INNER JOIN "users" "users_2" "users"."id" = "users_2"."id"
|
INNER JOIN "users" "users_2" "users"."id" = "users_2"."id"
|
||||||
}
|
}
|
||||||
manager.joins(manager).must_equal manager.join_sql
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns outer join sql' do
|
it 'returns outer join sql' do
|
||||||
|
@ -323,7 +322,6 @@ module Arel
|
||||||
manager.join_sql.must_be_like %{
|
manager.join_sql.must_be_like %{
|
||||||
LEFT OUTER JOIN "users" "users_2" "users"."id" = "users_2"."id"
|
LEFT OUTER JOIN "users" "users_2" "users"."id" = "users_2"."id"
|
||||||
}
|
}
|
||||||
manager.joins(manager).must_equal manager.join_sql
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns string join sql' do
|
it 'returns string join sql' do
|
||||||
|
@ -331,7 +329,6 @@ module Arel
|
||||||
manager = Arel::SelectManager.new Table.engine
|
manager = Arel::SelectManager.new Table.engine
|
||||||
manager.from Nodes::StringJoin.new(table, 'hello')
|
manager.from Nodes::StringJoin.new(table, 'hello')
|
||||||
manager.join_sql.must_be_like %{ 'hello' }
|
manager.join_sql.must_be_like %{ 'hello' }
|
||||||
manager.joins(manager).must_equal manager.join_sql
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns nil join sql' do
|
it 'returns nil join sql' do
|
||||||
|
@ -436,9 +433,9 @@ module Arel
|
||||||
manager = Arel::SelectManager.new engine
|
manager = Arel::SelectManager.new engine
|
||||||
manager.from table
|
manager.from table
|
||||||
manager.take 1
|
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
|
UPDATE "users" SET foo = bar
|
||||||
WHERE "users"."id" IN (SELECT "users"."id" FROM "users" LIMIT 1)
|
WHERE "users"."id" IN (SELECT "users"."id" FROM "users" LIMIT 1)
|
||||||
}
|
}
|
||||||
|
@ -450,9 +447,9 @@ module Arel
|
||||||
manager = Arel::SelectManager.new engine
|
manager = Arel::SelectManager.new engine
|
||||||
manager.from table
|
manager.from table
|
||||||
manager.order :foo
|
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
|
UPDATE "users" SET foo = bar
|
||||||
WHERE "users"."id" IN (SELECT "users"."id" FROM "users" ORDER BY foo)
|
WHERE "users"."id" IN (SELECT "users"."id" FROM "users" ORDER BY foo)
|
||||||
}
|
}
|
||||||
|
@ -463,9 +460,9 @@ module Arel
|
||||||
table = Table.new :users
|
table = Table.new :users
|
||||||
manager = Arel::SelectManager.new engine
|
manager = Arel::SelectManager.new engine
|
||||||
manager.from table
|
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
|
end
|
||||||
|
|
||||||
it 'copies where clauses' do
|
it 'copies where clauses' do
|
||||||
|
@ -474,9 +471,9 @@ module Arel
|
||||||
manager = Arel::SelectManager.new engine
|
manager = Arel::SelectManager.new engine
|
||||||
manager.where table[:id].eq 10
|
manager.where table[:id].eq 10
|
||||||
manager.from table
|
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
|
UPDATE "users" SET "id" = 1 WHERE "users"."id" = 10
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -486,9 +483,9 @@ module Arel
|
||||||
table = Table.new :users
|
table = Table.new :users
|
||||||
manager = Arel::SelectManager.new engine
|
manager = Arel::SelectManager.new engine
|
||||||
manager.from table
|
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
|
UPDATE "users" SET "id" = 1
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,12 +48,6 @@ module Arel
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'backwards compat' do
|
describe 'backwards compat' do
|
||||||
describe 'joins' do
|
|
||||||
it 'returns nil' do
|
|
||||||
@relation.joins(nil).must_equal nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'join' do
|
describe 'join' do
|
||||||
it 'noops on nil' do
|
it 'noops on nil' do
|
||||||
mgr = @relation.join nil
|
mgr = @relation.join nil
|
||||||
|
|
Loading…
Reference in a new issue