Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
5558bb0d
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,发现更多精彩内容 >>
提交
5558bb0d
编写于
3月 15, 2013
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9733 from senny/9712_option_to_turn_references_deprecation_off
make it possible to disable implicit join references.
上级
133a1759
34402c76
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
38 addition
and
2 deletion
+38
-2
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+15
-0
activerecord/lib/active_record/core.rb
activerecord/lib/active_record/core.rb
+8
-0
activerecord/lib/active_record/relation.rb
activerecord/lib/active_record/relation.rb
+6
-2
activerecord/test/cases/relations_test.rb
activerecord/test/cases/relations_test.rb
+9
-0
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
5558bb0d
## Rails 4.0.0 (unreleased) ##
*
Referencing join tables implicitly was deprecated. There is a
possibility that these deprecation warnings are shown even if you
don't make use of that feature. You can now disable the feature entirely.
Fixes #9712.
Example:
# in your configuration
config.active_record.disable_implicit_join_references = true
# or directly
ActiveRecord::Base.disable_implicit_join_references = true
*Yves Senn*
*
The
`:distinct`
option for
`Relation#count`
is deprecated. You
should use
`Relation#distinct`
instead.
...
...
activerecord/lib/active_record/core.rb
浏览文件 @
5558bb0d
...
...
@@ -69,6 +69,14 @@ module Core
mattr_accessor
:timestamped_migrations
,
instance_writer:
false
self
.
timestamped_migrations
=
true
##
# :singleton-method:
# Disable implicit join references. This feature was deprecated with Rails 4.
# If you don't make use of implicit references but still see deprecation warnings
# you can disable the feature entirely. This will be the default with Rails 4.1.
mattr_accessor
:disable_implicit_join_references
,
instance_writer:
false
self
.
disable_implicit_join_references
=
false
class_attribute
:connection_handler
,
instance_writer:
false
self
.
connection_handler
=
ConnectionAdapters
::
ConnectionHandler
.
new
end
...
...
activerecord/lib/active_record/relation.rb
浏览文件 @
5558bb0d
...
...
@@ -595,7 +595,8 @@ def references_eager_loaded_tables?
if
(
references_values
-
joined_tables
).
any?
true
elsif
(
string_tables
-
joined_tables
).
any?
elsif
!
ActiveRecord
::
Base
.
disable_implicit_join_references
&&
(
string_tables
-
joined_tables
).
any?
ActiveSupport
::
Deprecation
.
warn
(
"It looks like you are eager loading table(s) (one of:
#{
string_tables
.
join
(
', '
)
}
) "
\
"that are referenced in a string SQL snippet. For example:
\n
"
\
...
...
@@ -609,7 +610,10 @@ def references_eager_loaded_tables?
"From now on, you must explicitly tell Active Record when you are referencing a table "
\
"from a string:
\n
"
\
"
\n
"
\
" Post.includes(:comments).where(
\"
comments.title = 'foo'
\"
).references(:comments)
\n\n
"
" Post.includes(:comments).where(
\"
comments.title = 'foo'
\"
).references(:comments)
\n
"
\
"
\n
"
\
"If you don't rely on implicit join references you can disable the feature entirely"
\
"by setting `config.active_record.disable_implicit_join_references = true`."
)
true
else
...
...
activerecord/test/cases/relations_test.rb
浏览文件 @
5558bb0d
...
...
@@ -1224,6 +1224,15 @@ def test_eager_loading_with_conditions_on_joins
end
end
def
test_turn_off_eager_loading_with_conditions_on_joins
original_value
=
ActiveRecord
::
Base
.
disable_implicit_join_references
ActiveRecord
::
Base
.
disable_implicit_join_references
=
true
scope
=
Topic
.
where
(
author_email_address:
'my.example@gmail.com'
).
includes
(
:replies
)
assert_not
scope
.
eager_loading?
ensure
ActiveRecord
::
Base
.
time_zone_aware_attributes
=
original_value
end
def
test_ordering_with_extra_spaces
assert_equal
authors
(
:david
),
Author
.
order
(
'id DESC , name DESC'
).
last
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录