Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4aad2894
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,发现更多精彩内容 >>
提交
4aad2894
编写于
11月 29, 2011
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make sure the original_foo accessor still works (but deprecated) if we are using self.foo=
上级
e51ecfaa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
86 addition
and
13 deletion
+86
-13
activerecord/lib/active_record/base.rb
activerecord/lib/active_record/base.rb
+31
-6
activerecord/test/cases/base_test.rb
activerecord/test/cases/base_test.rb
+55
-7
未找到文件。
activerecord/lib/active_record/base.rb
浏览文件 @
4aad2894
...
...
@@ -604,6 +604,16 @@ def deprecated_property_setter(property, value, block) #:nodoc:
end
end
def
deprecated_original_property_getter
(
property
)
#:nodoc:
ActiveSupport
::
Deprecation
.
warn
(
"original_
#{
property
}
is deprecated. Define self.
#{
property
}
and call super instead."
)
if
!
instance_variable_defined?
(
"@original_
#{
property
}
"
)
&&
respond_to?
(
"reset_
#{
property
}
"
)
send
(
"reset_
#{
property
}
"
)
else
instance_variable_get
(
"@original_
#{
property
}
"
)
end
end
# Guesses the table name (in forced lower-case) based on the name of the class in the
# inheritance hierarchy descending directly from ActiveRecord::Base. So if the hierarchy
# looks like: Reply < Message < ActiveRecord::Base, then Message is used
...
...
@@ -664,6 +674,10 @@ def table_name
@table_name
end
def
original_table_name
#:nodoc:
deprecated_original_property_getter
:table_name
end
# Sets the table name explicitly. Example:
#
# class Project < ActiveRecord::Base
...
...
@@ -673,10 +687,11 @@ def table_name
# You can also just define your own <tt>self.table_name</tt> method; see
# the documentation for ActiveRecord::Base#table_name.
def
table_name
=
(
value
)
@table_name
=
value
@quoted_table_name
=
nil
@arel_table
=
nil
@relation
=
Relation
.
new
(
self
,
arel_table
)
@original_table_name
=
@table_name
if
defined?
(
@table_name
)
@table_name
=
value
@quoted_table_name
=
nil
@arel_table
=
nil
@relation
=
Relation
.
new
(
self
,
arel_table
)
end
def
set_table_name
(
value
=
nil
,
&
block
)
#:nodoc:
...
...
@@ -715,9 +730,14 @@ def inheritance_column
end
end
def
original_inheritance_column
#:nodoc:
deprecated_original_property_getter
:inheritance_column
end
# Sets the value of inheritance_column
def
inheritance_column
=
(
value
)
@inheritance_column
=
value
.
to_s
@original_inheritance_column
=
inheritance_column
@inheritance_column
=
value
.
to_s
end
def
set_inheritance_column
(
value
=
nil
,
&
block
)
#:nodoc:
...
...
@@ -732,6 +752,10 @@ def sequence_name
end
end
def
original_sequence_name
#:nodoc:
deprecated_original_property_getter
:sequence_name
end
def
reset_sequence_name
#:nodoc:
self
.
sequence_name
=
connection
.
default_sequence_name
(
table_name
,
primary_key
)
end
...
...
@@ -751,7 +775,8 @@ def reset_sequence_name #:nodoc:
# self.sequence_name = "projectseq" # default would have been "project_seq"
# end
def
sequence_name
=
(
value
)
@sequence_name
=
value
.
to_s
@original_sequence_name
=
@sequence_name
if
defined?
(
@sequence_name
)
@sequence_name
=
value
.
to_s
end
def
set_sequence_name
(
value
=
nil
,
&
block
)
#:nodoc:
...
...
activerecord/test/cases/base_test.rb
浏览文件 @
4aad2894
...
...
@@ -1476,6 +1476,24 @@ def k.table_name; super + "ks"; end
assert_equal
"foosks"
,
k
.
table_name
end
def
test_original_table_name
k
=
Class
.
new
(
ActiveRecord
::
Base
)
def
k
.
name
;
"Foo"
;
end
k
.
table_name
=
"bar"
assert_deprecated
do
assert_equal
"foos"
,
k
.
original_table_name
end
k
=
Class
.
new
(
ActiveRecord
::
Base
)
k
.
table_name
=
"omg"
k
.
table_name
=
"wtf"
assert_deprecated
do
assert_equal
"omg"
,
k
.
original_table_name
end
end
def
test_set_primary_key_with_value
k
=
Class
.
new
(
ActiveRecord
::
Base
)
k
.
primary_key
=
"foo"
...
...
@@ -1510,6 +1528,16 @@ def test_set_inheritance_column_with_block
assert_equal
"type_id"
,
k
.
inheritance_column
end
def
test_original_inheritance_column
k
=
Class
.
new
(
ActiveRecord
::
Base
)
def
k
.
name
;
"Foo"
;
end
k
.
inheritance_column
=
"omg"
assert_deprecated
do
assert_equal
"type"
,
k
.
original_inheritance_column
end
end
def
test_set_sequence_name_with_value
k
=
Class
.
new
(
ActiveRecord
::
Base
)
k
.
sequence_name
=
"foo"
...
...
@@ -1525,14 +1553,34 @@ def test_set_sequence_name_with_block
k
=
Class
.
new
(
ActiveRecord
::
Base
)
k
.
table_name
=
"projects"
orig_name
=
k
.
sequence_name
return
skip
"sequences not supported by db"
unless
orig_name
if
orig_name
assert_deprecated
do
k
.
set_sequence_name
{
original_sequence_name
+
"_lol"
}
end
assert_equal
orig_name
+
"_lol"
,
k
.
sequence_name
else
skip
"sequences not supported by db"
assert_deprecated
do
k
.
set_sequence_name
{
original_sequence_name
+
"_lol"
}
end
assert_equal
orig_name
+
"_lol"
,
k
.
sequence_name
end
def
test_original_sequence_name
k
=
Class
.
new
(
ActiveRecord
::
Base
)
k
.
table_name
=
"projects"
orig_name
=
k
.
sequence_name
return
skip
"sequences not supported by db"
unless
orig_name
k
=
Class
.
new
(
ActiveRecord
::
Base
)
k
.
table_name
=
"projects"
k
.
sequence_name
=
"omg"
assert_deprecated
do
assert_equal
orig_name
,
k
.
original_sequence_name
end
k
=
Class
.
new
(
ActiveRecord
::
Base
)
k
.
table_name
=
"projects"
k
.
sequence_name
=
"omg"
k
.
sequence_name
=
"wtf"
assert_deprecated
do
assert_equal
"omg"
,
k
.
original_sequence_name
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录