Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3053e544
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,发现更多精彩内容 >>
未验证
提交
3053e544
编写于
4月 14, 2020
作者:
R
Rafael França
提交者:
GitHub
4月 14, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #38942 from joshmn/joshmn_fix_has_one_touch
Prevent has_one from touching parent record unless persisted
上级
0349dfc4
ba3ef762
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
27 addition
and
1 deletion
+27
-1
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+6
-0
activerecord/lib/active_record/associations/has_one_association.rb
...ord/lib/active_record/associations/has_one_association.rb
+3
-1
activerecord/test/cases/associations/has_one_associations_test.rb
...cord/test/cases/associations/has_one_associations_test.rb
+18
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
3053e544
*
Prevent
`build_association`
from
`touching`
a parent record if the record isn't persisted for
`has_one`
associations.
Fixes #38219
*Josh Brody*
*
Add support for
`if_not_exists`
option for adding index.
*
Add support for
`if_not_exists`
option for adding index.
The `add_index` method respects `if_not_exists` option. If it is set to true
The `add_index` method respects `if_not_exists` option. If it is set to true
...
...
activerecord/lib/active_record/associations/has_one_association.rb
浏览文件 @
3053e544
...
@@ -81,7 +81,9 @@ def remove_target!(method)
...
@@ -81,7 +81,9 @@ def remove_target!(method)
target
.
delete
target
.
delete
when
:destroy
when
:destroy
target
.
destroyed_by_association
=
reflection
target
.
destroyed_by_association
=
reflection
if
target
.
persisted?
target
.
destroy
target
.
destroy
end
else
else
nullify_owner_attributes
(
target
)
nullify_owner_attributes
(
target
)
remove_inverse_instance
(
target
)
remove_inverse_instance
(
target
)
...
...
activerecord/test/cases/associations/has_one_associations_test.rb
浏览文件 @
3053e544
...
@@ -851,4 +851,22 @@ def test_dependency_should_halt_parent_destruction
...
@@ -851,4 +851,22 @@ def test_dependency_should_halt_parent_destruction
assert_not
author
.
destroy
assert_not
author
.
destroy
end
end
end
end
class
SpecialCar
<
ActiveRecord
::
Base
self
.
table_name
=
"cars"
has_one
:special_bulb
,
inverse_of: :car
,
dependent: :destroy
,
class_name:
"SpecialBulb"
,
foreign_key:
"car_id"
end
class
SpecialBulb
<
ActiveRecord
::
Base
self
.
table_name
=
"bulbs"
belongs_to
:car
,
inverse_of: :special_bulb
,
touch:
true
,
class_name:
"SpecialCar"
end
def
test_has_one_with_touch_option_on_nonpersisted_built_associations_doesnt_update_parent
car
=
SpecialCar
.
create
(
name:
"honda"
)
assert_queries
(
1
)
do
car
.
build_special_bulb
car
.
build_special_bulb
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录