Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
8cbd5000
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 搜索 >>
提交
8cbd5000
编写于
1月 22, 2014
作者:
K
Keenan Brock
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move changed_attributes into dirty.rb
Move serialization dirty into serialization.rb
上级
72403003
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
47 addition
and
16 deletion
+47
-16
activerecord/lib/active_record/attribute_methods/dirty.rb
activerecord/lib/active_record/attribute_methods/dirty.rb
+21
-1
activerecord/lib/active_record/attribute_methods/serialization.rb
...cord/lib/active_record/attribute_methods/serialization.rb
+8
-0
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+2
-14
activerecord/lib/active_record/inheritance.rb
activerecord/lib/active_record/inheritance.rb
+10
-0
activerecord/lib/active_record/scoping.rb
activerecord/lib/active_record/scoping.rb
+5
-0
activerecord/lib/active_record/timestamp.rb
activerecord/lib/active_record/timestamp.rb
+1
-1
未找到文件。
activerecord/lib/active_record/attribute_methods/dirty.rb
浏览文件 @
8cbd5000
...
...
@@ -38,7 +38,27 @@ def reload(*)
end
end
def
initialize_dup
(
other
)
# :nodoc:
super
init_changed_attributes
end
private
def
initialize_internals_callback
super
init_changed_attributes
end
def
init_changed_attributes
@changed_attributes
=
nil
# Intentionally avoid using #column_defaults since overridden defaults (as is done in
# optimistic locking) won't get written unless they get marked as changed
self
.
class
.
columns
.
each
do
|
c
|
attr
,
orig_value
=
c
.
name
,
c
.
default
changed_attributes
[
attr
]
=
orig_value
if
_field_changed?
(
attr
,
orig_value
,
@attributes
[
attr
])
end
end
# Wrap write_attribute to remember original attribute value.
def
write_attribute
(
attr
,
value
)
attr
=
attr
.
to_s
...
...
@@ -67,7 +87,7 @@ def create_record(*)
# Serialized attributes should always be written in case they've been
# changed in place.
def
keys_for_partial_write
changed
|
(
attributes
.
keys
&
self
.
class
.
serialized_attributes
.
keys
)
changed
end
def
_field_changed?
(
attr
,
old
,
value
)
...
...
activerecord/lib/active_record/attribute_methods/serialization.rb
浏览文件 @
8cbd5000
...
...
@@ -115,6 +115,14 @@ def initialize_attributes(attributes, options = {})
end
end
def
should_record_timestamps?
super
||
(
self
.
record_timestamps
&&
(
attributes
.
keys
&
self
.
class
.
serialized_attributes
.
keys
).
present?
)
end
def
keys_for_partial_write
super
|
(
attributes
.
keys
&
self
.
class
.
serialized_attributes
.
keys
)
end
def
type_cast_attribute_for_write
(
column
,
value
)
if
column
&&
coder
=
self
.
class
.
serialized_attributes
[
column
.
name
]
Attribute
.
new
(
coder
,
value
,
:unserialized
)
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
8cbd5000
...
...
@@ -182,9 +182,7 @@ def initialize(attributes = nil, options = {})
@column_types
=
self
.
class
.
column_types
init_internals
init_changed_attributes
ensure_proper_type
populate_with_current_scope_attributes
initialize_internals_callback
# +options+ argument is only needed to make protected_attributes gem easier to hook.
# Remove it when we drop support to this gem.
...
...
@@ -255,16 +253,12 @@ def initialize_dup(other) # :nodoc:
run_callbacks
(
:initialize
)
unless
_initialize_callbacks
.
empty?
@changed_attributes
=
{}
init_changed_attributes
@aggregation_cache
=
{}
@association_cache
=
{}
@attributes_cache
=
{}
@new_record
=
true
ensure_proper_type
super
end
...
...
@@ -440,13 +434,7 @@ def init_internals
@reflects_state
=
[
false
]
end
def
init_changed_attributes
# Intentionally avoid using #column_defaults since overridden defaults (as is done in
# optimistic locking) won't get written unless they get marked as changed
self
.
class
.
columns
.
each
do
|
c
|
attr
,
orig_value
=
c
.
name
,
c
.
default
changed_attributes
[
attr
]
=
orig_value
if
_field_changed?
(
attr
,
orig_value
,
@attributes
[
attr
])
end
def
initialize_internals_callback
end
# This method is needed to make protected_attributes gem easier to hook.
...
...
activerecord/lib/active_record/inheritance.rb
浏览文件 @
8cbd5000
...
...
@@ -195,8 +195,18 @@ def subclass_from_attributes(attrs)
end
end
def
initialize_dup
(
other
)
super
ensure_proper_type
end
private
def
initialize_internals_callback
super
ensure_proper_type
end
# Sets the attribute used for single table inheritance to this class name if this is not the
# ActiveRecord::Base descendant.
# Considering the hierarchy Reply < Message < ActiveRecord::Base, this makes it possible to
...
...
activerecord/lib/active_record/scoping.rb
浏览文件 @
8cbd5000
...
...
@@ -27,6 +27,11 @@ def populate_with_current_scope_attributes
end
end
def
initialize_internals_callback
super
populate_with_current_scope_attributes
end
# This class stores the +:current_scope+ and +:ignore_default_scope+ values
# for different classes. The registry is stored as a thread local, which is
# accessed through +ScopeRegistry.current+.
...
...
activerecord/lib/active_record/timestamp.rb
浏览文件 @
8cbd5000
...
...
@@ -71,7 +71,7 @@ def update_record(*args)
end
def
should_record_timestamps?
self
.
record_timestamps
&&
(
!
partial_writes?
||
changed?
||
(
attributes
.
keys
&
self
.
class
.
serialized_attributes
.
keys
).
present?
)
self
.
record_timestamps
&&
(
!
partial_writes?
||
changed?
)
end
def
timestamp_attributes_for_create_in_model
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录