Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4a0d7c1a
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 搜索 >>
提交
4a0d7c1a
编写于
7月 14, 2010
作者:
S
Subba Rao Pasupuleti
提交者:
José Valim
7月 18, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
save on parent should not cascade to child unless child changed [#3353 state:resolved]
Signed-off-by:
N
José Valim
<
jose.valim@gmail.com
>
上级
e210895b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
1 deletion
+21
-1
activerecord/lib/active_record/autosave_association.rb
activerecord/lib/active_record/autosave_association.rb
+3
-1
activerecord/test/cases/autosave_association_test.rb
activerecord/test/cases/autosave_association_test.rb
+18
-0
未找到文件。
activerecord/lib/active_record/autosave_association.rb
浏览文件 @
4a0d7c1a
...
...
@@ -372,7 +372,9 @@ def save_belongs_to_association(reflection)
if
autosave
&&
association
.
marked_for_destruction?
association
.
destroy
elsif
autosave
!=
false
saved
=
association
.
save
(
:validate
=>
!
autosave
)
if
association
.
new_record?
||
autosave
if
association
.
new_record?
||
(
autosave
&&
association
.
changed?
)
saved
=
association
.
save
(
:validate
=>
!
autosave
)
end
if
association
.
updated?
association_id
=
association
.
send
(
reflection
.
options
[
:primary_key
]
||
:id
)
...
...
activerecord/test/cases/autosave_association_test.rb
浏览文件 @
4a0d7c1a
...
...
@@ -632,6 +632,8 @@ def test_a_parent_marked_for_destruction_should_not_be_destroyed_twice
end
def
test_should_rollback_destructions_if_an_exception_occurred_while_saving_a_parent
#association save method only trigged when association is changed
@ship
.
pirate
.
catchphrase
=
"new catch phrase"
# Stub the save method of the @ship.pirate instance to destroy and then raise an exception
class
<<
@ship
.
pirate
def
save
(
*
args
)
...
...
@@ -880,6 +882,22 @@ def setup
@pirate
=
@ship
.
create_pirate
(
:catchphrase
=>
"Don' botharrr talkin' like one, savvy?"
)
end
def
test_should_not_call_belongs_to_after_save_callbacks_if_no_changes
@ship
.
attributes
=
{
:name
=>
"Titanic"
,
:pirate_attributes
=>
{
:id
=>
@pirate
.
id
}
}
#here there are no changes to pirate so if save on ship causes save on pirate
#this callback will fail pirate save.(pirate save shouldn't happen)
@ship
.
pirate
.
cancel_save_from_callback
=
true
@ship
.
save
assert_equal
'Titanic'
,
@ship
.
reload
.
name
end
def
test_should_call_belongs_to_save_if_belongs_to_has_changes
@ship
.
attributes
=
{
:name
=>
"Titanic"
,
:pirate_attributes
=>
{
:catchphrase
=>
'Jack'
,
:id
=>
@pirate
.
id
}
}
@ship
.
save
assert_equal
'Titanic'
,
@ship
.
reload
.
name
assert_equal
'Jack'
,
@pirate
.
reload
.
catchphrase
end
def
test_should_still_work_without_an_associated_model
@pirate
.
destroy
@ship
.
reload
.
name
=
"The Vile Insanity"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录