Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
1bbb520f
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,发现更多精彩内容 >>
提交
1bbb520f
编写于
6月 05, 2019
作者:
E
Eileen M. Uchitelle
提交者:
eileencodes
6月 05, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge pull request #36394 from eileencodes/treat-application-record-as-primary
Treat ActiveRecord::Base and ApplicationRecord as "primary"
上级
5de554e7
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
22 addition
and
5 deletion
+22
-5
activerecord/lib/active_record/connection_handling.rb
activerecord/lib/active_record/connection_handling.rb
+6
-2
activerecord/test/cases/connection_adapters/connection_handler_test.rb
...test/cases/connection_adapters/connection_handler_test.rb
+13
-0
railties/test/application/loading_test.rb
railties/test/application/loading_test.rb
+3
-3
未找到文件。
activerecord/lib/active_record/connection_handling.rb
浏览文件 @
1bbb520f
...
...
@@ -173,7 +173,7 @@ def resolve_config_for_connection(config_or_env) # :nodoc:
raise
"Anonymous class is not allowed."
unless
name
config_or_env
||=
DEFAULT_ENV
.
call
.
to_sym
pool_name
=
self
==
Base
?
"primary"
:
name
pool_name
=
primary_class?
?
"primary"
:
name
self
.
connection_specification_name
=
pool_name
resolver
=
ConnectionAdapters
::
ConnectionSpecification
::
Resolver
.
new
(
Base
.
configurations
)
...
...
@@ -204,11 +204,15 @@ def connection
# Return the specification name from the current class or its parent.
def
connection_specification_name
if
!
defined?
(
@connection_specification_name
)
||
@connection_specification_name
.
nil?
return
self
==
Base
?
"primary"
:
superclass
.
connection_specification_name
return
primary_class?
?
"primary"
:
superclass
.
connection_specification_name
end
@connection_specification_name
end
def
primary_class?
# :nodoc:
self
==
Base
||
defined?
(
ApplicationRecord
)
&&
self
==
ApplicationRecord
end
# Returns the configuration of the associated connection as a hash:
#
# ActiveRecord::Base.connection_config
...
...
activerecord/test/cases/connection_adapters/connection_handler_test.rb
浏览文件 @
1bbb520f
...
...
@@ -367,11 +367,24 @@ def test_a_class_using_custom_pool_and_switching_back_to_primary
assert_same
klass2
.
connection
,
ActiveRecord
::
Base
.
connection
end
class
ApplicationRecord
<
ActiveRecord
::
Base
self
.
abstract_class
=
true
end
class
MyClass
<
ApplicationRecord
end
def
test_connection_specification_name_should_fallback_to_parent
klassA
=
Class
.
new
(
Base
)
klassB
=
Class
.
new
(
klassA
)
klassC
=
Class
.
new
(
MyClass
)
assert_equal
klassB
.
connection_specification_name
,
klassA
.
connection_specification_name
assert_equal
klassC
.
connection_specification_name
,
klassA
.
connection_specification_name
assert_equal
"primary"
,
klassA
.
connection_specification_name
assert_equal
"primary"
,
klassC
.
connection_specification_name
klassA
.
connection_specification_name
=
"readonly"
assert_equal
"readonly"
,
klassB
.
connection_specification_name
end
...
...
railties/test/application/loading_test.rb
浏览文件 @
1bbb520f
...
...
@@ -116,7 +116,7 @@ class User < ActiveRecord::Base
RUBY
app_file
"app/models/post.rb"
,
<<-
MODEL
class Post < A
ctiveRecord::Base
class Post < A
pplicationRecord
end
MODEL
...
...
@@ -133,9 +133,9 @@ class Post < ActiveRecord::Base
require
"
#{
rails_root
}
/config/environment"
setup_ar!
assert_equal
[
ActiveStorage
::
Blob
,
ActiveStorage
::
Attachment
,
ActiveRecord
::
SchemaMigration
,
ActiveRecord
::
InternalMetadata
].
collect
(
&
:to_s
).
sort
,
ActiveRecord
::
Base
.
descendants
.
collect
(
&
:to_s
).
sort
assert_equal
[
ActiveStorage
::
Blob
,
ActiveStorage
::
Attachment
,
ActiveRecord
::
SchemaMigration
,
ActiveRecord
::
InternalMetadata
,
ApplicationRecord
].
collect
(
&
:to_s
).
sort
,
ActiveRecord
::
Base
.
descendants
.
collect
(
&
:to_s
).
sort
get
"/load"
assert_equal
[
ActiveStorage
::
Blob
,
ActiveStorage
::
Attachment
,
ActiveRecord
::
SchemaMigration
,
ActiveRecord
::
InternalMetadata
,
Post
].
collect
(
&
:to_s
).
sort
,
ActiveRecord
::
Base
.
descendants
.
collect
(
&
:to_s
).
sort
assert_equal
[
ActiveStorage
::
Blob
,
ActiveStorage
::
Attachment
,
ActiveRecord
::
SchemaMigration
,
ActiveRecord
::
InternalMetadata
,
ApplicationRecord
,
Post
].
collect
(
&
:to_s
).
sort
,
ActiveRecord
::
Base
.
descendants
.
collect
(
&
:to_s
).
sort
get
"/unload"
assert_equal
[
ActiveStorage
::
Blob
,
ActiveStorage
::
Attachment
,
ActiveRecord
::
SchemaMigration
,
ActiveRecord
::
InternalMetadata
].
collect
(
&
:to_s
).
sort
,
ActiveRecord
::
Base
.
descendants
.
collect
(
&
:to_s
).
sort
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录