Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3bc747bd
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,发现更多精彩内容 >>
提交
3bc747bd
编写于
1月 09, 2017
作者:
K
Kasper Timm Hansen
提交者:
GitHub
1月 09, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #27551 from kirs/deprecate-class-name-as-class
Deprecate reflection class name to accept a class
上级
2b555ee9
8312a0d2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
27 addition
and
3 deletion
+27
-3
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+5
-0
activerecord/lib/active_record/reflection.rb
activerecord/lib/active_record/reflection.rb
+11
-0
activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
...associations/has_and_belongs_to_many_associations_test.rb
+4
-2
activerecord/test/cases/reflection_test.rb
activerecord/test/cases/reflection_test.rb
+6
-0
activerecord/test/models/user.rb
activerecord/test/models/user.rb
+1
-1
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
3bc747bd
*
Deprecate passing a class to the
`class_name`
because it eagerloads more classes than
necessary and potentially creates circular dependencies.
*Kir Shatrov*
*
Raise error when has_many through is defined before through association
*
Raise error when has_many through is defined before through association
Fixes #26834
Fixes #26834
...
...
activerecord/lib/active_record/reflection.rb
浏览文件 @
3bc747bd
...
@@ -364,6 +364,17 @@ def initialize(name, scope, options, active_record)
...
@@ -364,6 +364,17 @@ def initialize(name, scope, options, active_record)
@constructable
=
calculate_constructable
(
macro
,
options
)
@constructable
=
calculate_constructable
(
macro
,
options
)
@association_scope_cache
=
{}
@association_scope_cache
=
{}
@scope_lock
=
Mutex
.
new
@scope_lock
=
Mutex
.
new
if
options
[
:class_name
]
&&
options
[
:class_name
].
class
==
Class
ActiveSupport
::
Deprecation
.
warn
(
<<-
MSG
.
squish
)
Passing a class to the `class_name` is deprecated and will raise
an ArgumentError in Rails 5.2. It eagerloads more classes than
necessary and potentially creates circular dependencies.
Please pass the class name as a string:
`belongs_to :client, class_name: 'Company'`
MSG
end
end
end
def
association_scope_cache
(
conn
,
owner
)
def
association_scope_cache
(
conn
,
owner
)
...
...
activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
浏览文件 @
3bc747bd
...
@@ -86,8 +86,10 @@ class DeveloperWithSymbolClassName < Developer
...
@@ -86,8 +86,10 @@ class DeveloperWithSymbolClassName < Developer
has_and_belongs_to_many
:projects
,
class_name: :ProjectWithSymbolsForKeys
has_and_belongs_to_many
:projects
,
class_name: :ProjectWithSymbolsForKeys
end
end
class
DeveloperWithConstantClassName
<
Developer
ActiveSupport
::
Deprecation
.
silence
do
has_and_belongs_to_many
:projects
,
class_name:
ProjectWithSymbolsForKeys
class
DeveloperWithConstantClassName
<
Developer
has_and_belongs_to_many
:projects
,
class_name:
ProjectWithSymbolsForKeys
end
end
end
class
DeveloperWithExtendOption
<
Developer
class
DeveloperWithExtendOption
<
Developer
...
...
activerecord/test/cases/reflection_test.rb
浏览文件 @
3bc747bd
...
@@ -404,6 +404,12 @@ def test_symbol_for_class_name
...
@@ -404,6 +404,12 @@ def test_symbol_for_class_name
assert_equal
Client
,
Firm
.
reflect_on_association
(
:unsorted_clients_with_symbol
).
klass
assert_equal
Client
,
Firm
.
reflect_on_association
(
:unsorted_clients_with_symbol
).
klass
end
end
def
test_class_for_class_name
assert_deprecated
do
assert_predicate
ActiveRecord
::
Reflection
.
create
(
:has_many
,
:clients
,
nil
,
{
class_name:
Client
},
Firm
),
:validate?
end
end
def
test_join_table
def
test_join_table
category
=
Struct
.
new
(
:table_name
,
:pluralize_table_names
).
new
(
"categories"
,
true
)
category
=
Struct
.
new
(
:table_name
,
:pluralize_table_names
).
new
(
"categories"
,
true
)
product
=
Struct
.
new
(
:table_name
,
:pluralize_table_names
).
new
(
"products"
,
true
)
product
=
Struct
.
new
(
:table_name
,
:pluralize_table_names
).
new
(
"products"
,
true
)
...
...
activerecord/test/models/user.rb
浏览文件 @
3bc747bd
...
@@ -5,7 +5,7 @@ class User < ActiveRecord::Base
...
@@ -5,7 +5,7 @@ class User < ActiveRecord::Base
has_secure_token
:auth_token
has_secure_token
:auth_token
has_and_belongs_to_many
:jobs_pool
,
has_and_belongs_to_many
:jobs_pool
,
class_name:
Job
,
class_name:
"Job"
,
join_table:
"jobs_pool"
join_table:
"jobs_pool"
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录