Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
609c58bf
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 搜索 >>
提交
609c58bf
编写于
12月 04, 2018
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #34609 from kamipo/delete_all_on_collection_proxy
Ensure that `delete_all` on collection proxy returns affected count
上级
53d5a682
4d7354aa
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
23 addition
and
6 deletion
+23
-6
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/associations/has_many_association.rb
...rd/lib/active_record/associations/has_many_association.rb
+1
-0
activerecord/lib/active_record/associations/has_many_through_association.rb
...ctive_record/associations/has_many_through_association.rb
+2
-0
activerecord/test/cases/associations/has_many_associations_test.rb
...ord/test/cases/associations/has_many_associations_test.rb
+13
-3
activerecord/test/cases/associations/has_many_through_associations_test.rb
.../cases/associations/has_many_through_associations_test.rb
+3
-3
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
609c58bf
*
Ensure that
`delete_all`
on collection proxy returns affected count.
*Ryuta Kamizono*
*
Reset scope after delete on collection association to clear stale offsets of removed records.
*Gannon McGibbon*
...
...
activerecord/lib/active_record/associations/has_many_association.rb
浏览文件 @
609c58bf
...
...
@@ -99,6 +99,7 @@ def delete_count(method, scope)
def
delete_or_nullify_all_records
(
method
)
count
=
delete_count
(
method
,
scope
)
update_counter
(
-
count
)
count
end
# Deletes the records according to the <tt>:dependent</tt> option.
...
...
activerecord/lib/active_record/associations/has_many_through_association.rb
浏览文件 @
609c58bf
...
...
@@ -161,6 +161,8 @@ def delete_records(records, method)
else
update_counter
(
-
count
)
end
count
end
def
difference
(
a
,
b
)
...
...
activerecord/test/cases/associations/has_many_associations_test.rb
浏览文件 @
609c58bf
...
...
@@ -264,7 +264,7 @@ def test_do_not_call_callbacks_for_delete_all
car
=
Car
.
create
(
name:
"honda"
)
car
.
funky_bulbs
.
create!
assert_equal
1
,
car
.
funky_bulbs
.
count
assert_
nothing_raised
{
car
.
reload
.
funky_bulbs
.
delete_all
}
assert_
equal
1
,
car
.
reload
.
funky_bulbs
.
delete_all
assert_equal
0
,
car
.
funky_bulbs
.
count
,
"bulbs should have been deleted using :delete_all strategy"
end
...
...
@@ -1413,7 +1413,7 @@ def test_delete_all
assert_equal
3
,
clients
.
count
assert_difference
"Client.count"
,
-
(
clients
.
count
)
do
companies
(
:first_firm
).
dependent_clients_of_firm
.
delete_all
assert_equal
clients
.
count
,
companies
(
:first_firm
).
dependent_clients_of_firm
.
delete_all
end
end
...
...
@@ -1510,10 +1510,20 @@ def test_clearing_a_dependent_association_collection
def
test_delete_all_with_option_delete_all
firm
=
companies
(
:first_firm
)
client_id
=
firm
.
dependent_clients_of_firm
.
first
.
id
firm
.
dependent_clients_of_firm
.
delete_all
(
:delete_all
)
count
=
firm
.
dependent_clients_of_firm
.
count
assert_equal
count
,
firm
.
dependent_clients_of_firm
.
delete_all
(
:delete_all
)
assert_nil
Client
.
find_by_id
(
client_id
)
end
def
test_delete_all_with_option_nullify
firm
=
companies
(
:first_firm
)
client_id
=
firm
.
dependent_clients_of_firm
.
first
.
id
count
=
firm
.
dependent_clients_of_firm
.
count
assert_equal
firm
,
Client
.
find
(
client_id
).
firm
assert_equal
count
,
firm
.
dependent_clients_of_firm
.
delete_all
(
:nullify
)
assert_nil
Client
.
find
(
client_id
).
firm
end
def
test_delete_all_accepts_limited_parameters
firm
=
companies
(
:first_firm
)
assert_raise
(
ArgumentError
)
do
...
...
activerecord/test/cases/associations/has_many_through_associations_test.rb
浏览文件 @
609c58bf
...
...
@@ -200,7 +200,7 @@ def test_delete_all_for_with_dependent_option_destroy
assert_no_difference
"Job.count"
do
assert_difference
"Reference.count"
,
-
1
do
person
.
reload
.
jobs_with_dependent_destroy
.
delete_all
assert_equal
1
,
person
.
reload
.
jobs_with_dependent_destroy
.
delete_all
end
end
end
...
...
@@ -211,7 +211,7 @@ def test_delete_all_for_with_dependent_option_nullify
assert_no_difference
"Job.count"
do
assert_no_difference
"Reference.count"
do
person
.
reload
.
jobs_with_dependent_nullify
.
delete_all
assert_equal
1
,
person
.
reload
.
jobs_with_dependent_nullify
.
delete_all
end
end
end
...
...
@@ -222,7 +222,7 @@ def test_delete_all_for_with_dependent_option_delete_all
assert_no_difference
"Job.count"
do
assert_difference
"Reference.count"
,
-
1
do
person
.
reload
.
jobs_with_dependent_delete_all
.
delete_all
assert_equal
1
,
person
.
reload
.
jobs_with_dependent_delete_all
.
delete_all
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录