Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
503bee01
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,发现更多精彩内容 >>
提交
503bee01
编写于
8月 20, 2012
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
initialize instance variables for transactions to remove conditionals
上级
075b9145
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
7 addition
and
8 deletion
+7
-8
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+1
-0
activerecord/lib/active_record/transactions.rb
activerecord/lib/active_record/transactions.rb
+6
-8
未找到文件。
activerecord/lib/active_record/core.rb
浏览文件 @
503bee01
...
@@ -393,6 +393,7 @@ def init_internals
...
@@ -393,6 +393,7 @@ def init_internals
@marked_for_destruction
=
false
@marked_for_destruction
=
false
@new_record
=
true
@new_record
=
true
@mass_assignment_options
=
nil
@mass_assignment_options
=
nil
@_start_transaction_state
=
{}
end
end
end
end
end
end
activerecord/lib/active_record/transactions.rb
浏览文件 @
503bee01
...
@@ -308,7 +308,6 @@ def with_transaction_returning_status
...
@@ -308,7 +308,6 @@ def with_transaction_returning_status
# Save the new record state and id of a record so it can be restored later if a transaction fails.
# Save the new record state and id of a record so it can be restored later if a transaction fails.
def
remember_transaction_record_state
#:nodoc:
def
remember_transaction_record_state
#:nodoc:
@_start_transaction_state
||=
{}
@_start_transaction_state
[
:id
]
=
id
if
has_attribute?
(
self
.
class
.
primary_key
)
@_start_transaction_state
[
:id
]
=
id
if
has_attribute?
(
self
.
class
.
primary_key
)
@_start_transaction_state
[
:new_record
]
=
@new_record
@_start_transaction_state
[
:new_record
]
=
@new_record
@_start_transaction_state
[
:destroyed
]
=
@destroyed
@_start_transaction_state
[
:destroyed
]
=
@destroyed
...
@@ -317,18 +316,16 @@ def remember_transaction_record_state #:nodoc:
...
@@ -317,18 +316,16 @@ def remember_transaction_record_state #:nodoc:
# Clear the new record state and id of a record.
# Clear the new record state and id of a record.
def
clear_transaction_record_state
#:nodoc:
def
clear_transaction_record_state
#:nodoc:
if
defined?
(
@_start_transaction_state
)
@_start_transaction_state
[
:level
]
=
(
@_start_transaction_state
[
:level
]
||
0
)
-
1
@_start_transaction_state
[
:level
]
=
(
@_start_transaction_state
[
:level
]
||
0
)
-
1
@_start_transaction_state
.
clear
if
@_start_transaction_state
[
:level
]
<
1
remove_instance_variable
(
:@_start_transaction_state
)
if
@_start_transaction_state
[
:level
]
<
1
end
end
end
# Restore the new record state and id of a record that was previously saved by a call to save_record_state.
# Restore the new record state and id of a record that was previously saved by a call to save_record_state.
def
restore_transaction_record_state
(
force
=
false
)
#:nodoc:
def
restore_transaction_record_state
(
force
=
false
)
#:nodoc:
if
defined?
(
@_start_transaction_state
)
unless
@_start_transaction_state
.
empty?
@_start_transaction_state
[
:level
]
=
(
@_start_transaction_state
[
:level
]
||
0
)
-
1
@_start_transaction_state
[
:level
]
=
(
@_start_transaction_state
[
:level
]
||
0
)
-
1
if
@_start_transaction_state
[
:level
]
<
1
||
force
if
@_start_transaction_state
[
:level
]
<
1
||
force
restore_state
=
remove_instance_variable
(
:@_start_transaction_state
)
restore_state
=
@_start_transaction_state
was_frozen
=
@attributes
.
frozen?
was_frozen
=
@attributes
.
frozen?
@attributes
=
@attributes
.
dup
if
was_frozen
@attributes
=
@attributes
.
dup
if
was_frozen
@new_record
=
restore_state
[
:new_record
]
@new_record
=
restore_state
[
:new_record
]
...
@@ -340,13 +337,14 @@ def restore_transaction_record_state(force = false) #:nodoc:
...
@@ -340,13 +337,14 @@ def restore_transaction_record_state(force = false) #:nodoc:
@attributes_cache
.
delete
(
self
.
class
.
primary_key
)
@attributes_cache
.
delete
(
self
.
class
.
primary_key
)
end
end
@attributes
.
freeze
if
was_frozen
@attributes
.
freeze
if
was_frozen
@_start_transaction_state
.
clear
end
end
end
end
end
end
# Determine if a record was created or destroyed in a transaction. State should be one of :new_record or :destroyed.
# Determine if a record was created or destroyed in a transaction. State should be one of :new_record or :destroyed.
def
transaction_record_state
(
state
)
#:nodoc:
def
transaction_record_state
(
state
)
#:nodoc:
@_start_transaction_state
[
state
]
if
defined?
(
@_start_transaction_state
)
@_start_transaction_state
[
state
]
end
end
# Determine if a transaction included an action for :create, :update, or :destroy. Used in filtering callbacks.
# Determine if a transaction included an action for :create, :update, or :destroy. Used in filtering callbacks.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录