Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
0d9f45ff
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 搜索 >>
提交
0d9f45ff
编写于
4月 02, 2018
作者:
B
Bogdan Gusiev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add AR::Base.base_class? predicate
上级
09b2348f
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
27 addition
and
9 deletion
+27
-9
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+4
-0
activerecord/lib/active_record/attribute_methods.rb
activerecord/lib/active_record/attribute_methods.rb
+1
-1
activerecord/lib/active_record/attribute_methods/primary_key.rb
...record/lib/active_record/attribute_methods/primary_key.rb
+1
-1
activerecord/lib/active_record/inheritance.rb
activerecord/lib/active_record/inheritance.rb
+7
-1
activerecord/lib/active_record/model_schema.rb
activerecord/lib/active_record/model_schema.rb
+3
-4
activerecord/lib/active_record/translation.rb
activerecord/lib/active_record/translation.rb
+1
-1
activerecord/test/cases/attribute_methods/read_test.rb
activerecord/test/cases/attribute_methods/read_test.rb
+1
-1
activerecord/test/cases/inheritance_test.rb
activerecord/test/cases/inheritance_test.rb
+9
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
0d9f45ff
*
Add
`AR::Base.base_class?`
predicate
*Bogdan Gusiev*
*
Add custom prefix option to ActiveRecord::Store.store_accessor.
*Tan Huynh*
...
...
activerecord/lib/active_record/attribute_methods.rb
浏览文件 @
0d9f45ff
...
...
@@ -59,7 +59,7 @@ def define_attribute_methods # :nodoc:
# attribute methods.
generated_attribute_methods
.
synchronize
do
return
false
if
@attribute_methods_generated
superclass
.
define_attribute_methods
unless
self
==
base_class
superclass
.
define_attribute_methods
unless
base_class?
super
(
attribute_names
)
@attribute_methods_generated
=
true
end
...
...
activerecord/lib/active_record/attribute_methods/primary_key.rb
浏览文件 @
0d9f45ff
...
...
@@ -83,7 +83,7 @@ def quoted_primary_key
end
def
reset_primary_key
#:nodoc:
if
self
==
base_class
if
base_class?
self
.
primary_key
=
get_primary_key
(
base_class
.
name
)
else
self
.
primary_key
=
base_class
.
primary_key
...
...
activerecord/lib/active_record/inheritance.rb
浏览文件 @
0d9f45ff
...
...
@@ -55,7 +55,7 @@ def new(attributes = nil, &block)
if
has_attribute?
(
inheritance_column
)
subclass
=
subclass_from_attributes
(
attributes
)
if
subclass
.
nil?
&&
base_class
==
self
if
subclass
.
nil?
&&
base_class
?
subclass
=
subclass_from_attributes
(
column_defaults
)
end
end
...
...
@@ -104,6 +104,12 @@ def base_class
end
end
# Returns whether the class is a base class.
# See #base_class for more information.
def
base_class?
base_class
==
self
end
# Set this to +true+ if this is an abstract class (see
# <tt>abstract_class?</tt>).
# If you are using inheritance with Active Record and don't want a class
...
...
activerecord/lib/active_record/model_schema.rb
浏览文件 @
0d9f45ff
...
...
@@ -276,7 +276,7 @@ def ignored_columns=(columns)
end
def
sequence_name
if
base_class
==
self
if
base_class
?
@sequence_name
||=
reset_sequence_name
else
(
@sequence_name
||=
nil
)
||
base_class
.
sequence_name
...
...
@@ -501,8 +501,7 @@ def undecorated_table_name(class_name = base_class.name)
# Computes and returns a table name according to default conventions.
def
compute_table_name
base
=
base_class
if
self
==
base
if
base_class?
# Nested classes are prefixed with singular parent table name.
if
parent
<
Base
&&
!
parent
.
abstract_class?
contained
=
parent
.
table_name
...
...
@@ -513,7 +512,7 @@ def compute_table_name
"
#{
full_table_name_prefix
}#{
contained
}#{
undecorated_table_name
(
name
)
}#{
full_table_name_suffix
}
"
else
# STI subclasses always use their superclass' table.
base
.
table_name
base
_class
.
table_name
end
end
end
...
...
activerecord/lib/active_record/translation.rb
浏览文件 @
0d9f45ff
...
...
@@ -10,7 +10,7 @@ def lookup_ancestors #:nodoc:
classes
=
[
klass
]
return
classes
if
klass
==
ActiveRecord
::
Base
while
klass
!=
klass
.
base_class
while
!
klass
.
base_class?
classes
<<
klass
=
klass
.
superclass
end
classes
...
...
activerecord/test/cases/attribute_methods/read_test.rb
浏览文件 @
0d9f45ff
...
...
@@ -12,7 +12,7 @@ def type; :integer; end
def
setup
@klass
=
Class
.
new
(
Class
.
new
{
def
self
.
initialize_generated_modules
;
end
})
do
def
self
.
superclass
;
Base
;
end
def
self
.
base_class
;
self
;
end
def
self
.
base_class
?
;
true
;
end
def
self
.
decorate_matching_attribute_types
(
*
);
end
include
ActiveRecord
::
DefineCallbacks
...
...
activerecord/test/cases/inheritance_test.rb
浏览文件 @
0d9f45ff
...
...
@@ -174,17 +174,26 @@ def test_abstract_class
def
test_inheritance_base_class
assert_equal
Post
,
Post
.
base_class
assert_predicate
Post
,
:base_class?
assert_equal
Post
,
SpecialPost
.
base_class
assert_not_predicate
SpecialPost
,
:base_class?
assert_equal
Post
,
StiPost
.
base_class
assert_not_predicate
StiPost
,
:base_class?
assert_equal
Post
,
SubStiPost
.
base_class
assert_not_predicate
SubStiPost
,
:base_class?
assert_equal
SubAbstractStiPost
,
SubAbstractStiPost
.
base_class
assert_predicate
SubAbstractStiPost
,
:base_class?
end
def
test_abstract_inheritance_base_class
assert_equal
LoosePerson
,
LoosePerson
.
base_class
assert_predicate
LoosePerson
,
:base_class?
assert_equal
LooseDescendant
,
LooseDescendant
.
base_class
assert_predicate
LooseDescendant
,
:base_class?
assert_equal
TightPerson
,
TightPerson
.
base_class
assert_predicate
TightPerson
,
:base_class?
assert_equal
TightPerson
,
TightDescendant
.
base_class
assert_not_predicate
TightDescendant
,
:base_class?
end
def
test_base_class_activerecord_error
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录