Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
93717f39
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,发现更多精彩内容 >>
提交
93717f39
编写于
9月 15, 2014
作者:
A
Alan Kennedy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't autosave unchanged has_one through records
上级
62955c77
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
1 deletion
+31
-1
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
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
+24
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
93717f39
*
Don't autosave unchanged has_one through records
*Alan Kennedy*, *Steve Parrington*
*
When a thread is killed, rollback the active transaction, instead of
*
When a thread is killed, rollback the active transaction, instead of
committing it during the stack unwind. Previously, we could commit half-
committing it during the stack unwind. Previously, we could commit half-
completed work. This fix only works for Ruby 2.0+; on 1.9, we can't
completed work. This fix only works for Ruby 2.0+; on 1.9, we can't
...
...
activerecord/lib/active_record/autosave_association.rb
浏览文件 @
93717f39
...
@@ -403,7 +403,9 @@ def save_has_one_association(reflection)
...
@@ -403,7 +403,9 @@ def save_has_one_association(reflection)
# If the record is new or it has changed, returns true.
# If the record is new or it has changed, returns true.
def
record_changed?
(
reflection
,
record
,
key
)
def
record_changed?
(
reflection
,
record
,
key
)
record
.
new_record?
||
record
[
reflection
.
foreign_key
]
!=
key
||
record
.
attribute_changed?
(
reflection
.
foreign_key
)
record
.
new_record?
||
(
record
.
attributes
.
keys
.
include?
(
reflection
.
foreign_key
)
&&
record
[
reflection
.
foreign_key
]
!=
key
)
||
record
.
attribute_changed?
(
reflection
.
foreign_key
)
end
end
# Saves the associated record if it's new or <tt>:autosave</tt> is enabled.
# Saves the associated record if it's new or <tt>:autosave</tt> is enabled.
...
...
activerecord/test/cases/autosave_association_test.rb
浏览文件 @
93717f39
...
@@ -19,6 +19,9 @@
...
@@ -19,6 +19,9 @@
require
'models/eye'
require
'models/eye'
require
'models/electron'
require
'models/electron'
require
'models/molecule'
require
'models/molecule'
require
'models/member'
require
'models/member_detail'
require
'models/organization'
class
TestAutosaveAssociationsInGeneral
<
ActiveRecord
::
TestCase
class
TestAutosaveAssociationsInGeneral
<
ActiveRecord
::
TestCase
def
test_autosave_validation
def
test_autosave_validation
...
@@ -1116,6 +1119,27 @@ def test_should_not_load_the_associated_model
...
@@ -1116,6 +1119,27 @@ def test_should_not_load_the_associated_model
end
end
end
end
class
TestAutosaveAssociationOnAHasOneThroughAssociation
<
ActiveRecord
::
TestCase
self
.
use_transactional_fixtures
=
false
unless
supports_savepoints?
def
setup
super
organization
=
Organization
.
create
@member
=
Member
.
create
MemberDetail
.
create
(
organization:
organization
,
member:
@member
)
end
def
test_should_not_has_one_through_model
class
<<
@member
.
organization
def
save
(
*
args
)
super
raise
'Oh noes!'
end
end
assert_nothing_raised
{
@member
.
save
}
end
end
class
TestAutosaveAssociationOnABelongsToAssociation
<
ActiveRecord
::
TestCase
class
TestAutosaveAssociationOnABelongsToAssociation
<
ActiveRecord
::
TestCase
self
.
use_transactional_fixtures
=
false
unless
supports_savepoints?
self
.
use_transactional_fixtures
=
false
unless
supports_savepoints?
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录