Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2f0c8c52
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2f0c8c52
编写于
4月 26, 2012
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove deprecate #update_all usage
上级
1606bee6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
6 addition
and
12 deletion
+6
-12
activerecord/lib/active_record/counter_cache.rb
activerecord/lib/active_record/counter_cache.rb
+1
-1
activerecord/lib/active_record/persistence.rb
activerecord/lib/active_record/persistence.rb
+2
-2
activerecord/test/cases/dirty_test.rb
activerecord/test/cases/dirty_test.rb
+2
-2
activerecord/test/cases/persistence_test.rb
activerecord/test/cases/persistence_test.rb
+1
-7
未找到文件。
activerecord/lib/active_record/counter_cache.rb
浏览文件 @
2f0c8c52
...
...
@@ -69,7 +69,7 @@ def update_counters(id, counters)
"
#{
quoted_column
}
= COALESCE(
#{
quoted_column
}
, 0)
#{
operator
}
#{
value
.
abs
}
"
end
update_all
(
updates
.
join
(
', '
),
primary_key
=>
id
)
where
(
primary_key
=>
id
).
update_all
updates
.
join
(
', '
)
end
# Increment a number field by one, usually representing a count.
...
...
activerecord/lib/active_record/persistence.rb
浏览文件 @
2f0c8c52
...
...
@@ -178,7 +178,7 @@ def update_column(name, value)
verify_readonly_attribute
(
name
)
raise
ActiveRecordError
,
"can not update on a new record object"
unless
persisted?
raw_write_attribute
(
name
,
value
)
self
.
class
.
update_all
({
name
=>
value
},
self
.
class
.
primary_key
=>
id
)
==
1
self
.
class
.
where
(
self
.
class
.
primary_key
=>
id
).
update_all
(
name
=>
value
)
==
1
end
# Updates the attributes of the model from the passed-in hash and saves the
...
...
@@ -313,7 +313,7 @@ def touch(name = nil)
@changed_attributes
.
except!
(
*
changes
.
keys
)
primary_key
=
self
.
class
.
primary_key
self
.
class
.
unscoped
.
update_all
(
changes
,
{
primary_key
=>
self
[
primary_key
]
}
)
==
1
self
.
class
.
unscoped
.
where
(
primary_key
=>
self
[
primary_key
]).
update_all
(
changes
)
==
1
end
end
...
...
activerecord/test/cases/dirty_test.rb
浏览文件 @
2f0c8c52
...
...
@@ -288,7 +288,7 @@ def test_partial_update
with_partial_updates
Pirate
,
false
do
assert_queries
(
2
)
{
2
.
times
{
pirate
.
save!
}
}
Pirate
.
update_all
({
:updated_on
=>
old_updated_on
},
:id
=>
pirate
.
id
)
Pirate
.
where
(
id:
pirate
.
id
).
update_all
(
:updated_on
=>
old_updated_on
)
end
with_partial_updates
Pirate
,
true
do
...
...
@@ -306,7 +306,7 @@ def test_partial_update_with_optimistic_locking
with_partial_updates
Person
,
false
do
assert_queries
(
2
)
{
2
.
times
{
person
.
save!
}
}
Person
.
update_all
({
:first_name
=>
'baz'
},
:id
=>
person
.
id
)
Person
.
where
(
id:
person
.
id
).
update_all
(
:first_name
=>
'baz'
)
end
with_partial_updates
Person
,
true
do
...
...
activerecord/test/cases/persistence_test.rb
浏览文件 @
2f0c8c52
...
...
@@ -94,12 +94,6 @@ def test_delete_all_with_joins_and_where_part_is_not_hash
assert_equal
count
,
Pet
.
joins
(
:toys
).
where
(
where_args
).
delete_all
end
def
test_update_by_condition
Topic
.
update_all
"content = 'bulk updated!'"
,
[
"approved = ?"
,
true
]
assert_equal
"Have a nice day"
,
Topic
.
find
(
1
).
content
assert_equal
"bulk updated!"
,
Topic
.
find
(
2
).
content
end
def
test_increment_attribute
assert_equal
50
,
accounts
(
:signals37
).
credit_limit
accounts
(
:signals37
).
increment!
:credit_limit
...
...
@@ -338,7 +332,7 @@ def test_update_all_with_hash
end
def
test_update_all_with_non_standard_table_name
assert_equal
1
,
WarehouseThing
.
update_all
([
'value = ?'
,
0
],
[
'id = ?'
,
1
])
assert_equal
1
,
WarehouseThing
.
where
(
id:
1
).
update_all
([
'value = ?'
,
0
])
assert_equal
0
,
WarehouseThing
.
find
(
1
).
value
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录