Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b1553fc4
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 搜索 >>
提交
b1553fc4
编写于
4月 30, 2019
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #36142 from kamipo/should_take_first_record_state
Should take the record's state of first action in the transaction
上级
6bbeecbc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
8 deletion
+11
-8
activerecord/lib/active_record/transactions.rb
activerecord/lib/active_record/transactions.rb
+9
-8
activerecord/test/cases/transaction_callbacks_test.rb
activerecord/test/cases/transaction_callbacks_test.rb
+2
-0
未找到文件。
activerecord/lib/active_record/transactions.rb
浏览文件 @
b1553fc4
...
...
@@ -333,7 +333,7 @@ def before_committed! # :nodoc:
# Ensure that it is not called if the object was never persisted (failed create),
# but call it after the commit of a destroyed object.
def
committed!
(
should_run_callbacks:
true
)
#:nodoc:
if
should_run_callbacks
&&
(
destroyed?
||
persisted?
)
if
should_run_callbacks
&&
trigger_transactional_callbacks?
@_committed_already_called
=
true
_run_commit_without_transaction_enrollment_callbacks
_run_commit_callbacks
...
...
@@ -346,7 +346,7 @@ def committed!(should_run_callbacks: true) #:nodoc:
# Call the #after_rollback callbacks. The +force_restore_state+ argument indicates if the record
# state should be rolled back to the beginning or just to the last savepoint.
def
rolledback!
(
force_restore_state:
false
,
should_run_callbacks:
true
)
#:nodoc:
if
should_run_callbacks
if
should_run_callbacks
&&
trigger_transactional_callbacks?
_run_rollback_callbacks
_run_rollback_without_transaction_enrollment_callbacks
end
...
...
@@ -364,7 +364,9 @@ def rolledback!(force_restore_state: false, should_run_callbacks: true) #:nodoc:
def
with_transaction_returning_status
status
=
nil
self
.
class
.
transaction
do
unless
has_transactional_callbacks?
if
has_transactional_callbacks?
add_to_transaction
else
sync_with_transaction_state
if
@transaction_state
&
.
finalized?
@transaction_state
=
self
.
class
.
connection
.
transaction_state
end
...
...
@@ -372,11 +374,6 @@ def with_transaction_returning_status
status
=
yield
raise
ActiveRecord
::
Rollback
unless
status
ensure
if
has_transactional_callbacks?
&&
(
@_new_record_before_last_commit
&&
!
new_record?
||
_trigger_update_callback
||
_trigger_destroy_callback
)
add_to_transaction
end
end
status
end
...
...
@@ -460,6 +457,10 @@ def add_to_transaction
self
.
class
.
connection
.
add_transaction_record
(
self
)
end
def
trigger_transactional_callbacks?
@_new_record_before_last_commit
&&
!
new_record?
||
_trigger_update_callback
||
_trigger_destroy_callback
end
def
has_transactional_callbacks?
!
_rollback_callbacks
.
empty?
||
!
_commit_callbacks
.
empty?
||
!
_before_commit_callbacks
.
empty?
end
...
...
activerecord/test/cases/transaction_callbacks_test.rb
浏览文件 @
b1553fc4
...
...
@@ -36,6 +36,8 @@ class TopicWithCallbacks < ActiveRecord::Base
has_many
:replies
,
class_name:
"ReplyWithCallbacks"
,
foreign_key:
"parent_id"
before_destroy
{
self
.
class
.
find
(
id
).
touch
if
persisted?
}
before_commit
{
|
record
|
record
.
do_before_commit
(
nil
)
}
after_commit
{
|
record
|
record
.
do_after_commit
(
nil
)
}
after_save_commit
{
|
record
|
record
.
do_after_commit
(
:save
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录