Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
56b4fdb5
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 搜索 >>
提交
56b4fdb5
编写于
4月 06, 2019
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Association loading isn't to be affected by null relation scoping
Follow up of #35868. Closes #19349.
上级
e9d1d766
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
3 deletion
+31
-3
activerecord/lib/active_record/relation.rb
activerecord/lib/active_record/relation.rb
+6
-2
activerecord/lib/active_record/scoping/named.rb
activerecord/lib/active_record/scoping/named.rb
+1
-1
activerecord/test/cases/scoping/relation_scoping_test.rb
activerecord/test/cases/scoping/relation_scoping_test.rb
+24
-0
未找到文件。
activerecord/lib/active_record/relation.rb
浏览文件 @
56b4fdb5
...
...
@@ -689,7 +689,7 @@ def inspect
end
def
empty_scope?
# :nodoc:
@values
==
klass
.
unscoped
.
values
!
null_relation?
&&
@values
==
klass
.
unscoped
.
values
end
def
has_limit_or_offset?
# :nodoc:
...
...
@@ -721,6 +721,10 @@ def load_records(records)
@loaded
=
true
end
def
null_relation?
# :nodoc:
is_a?
(
NullRelation
)
end
private
def
already_in_scope?
@delegate_to_klass
&&
begin
...
...
@@ -770,7 +774,7 @@ def exec_queries(&block)
@records
=
if
eager_loading?
apply_join_dependency
do
|
relation
,
join_dependency
|
if
ActiveRecord
::
NullRelation
===
relation
if
relation
.
null_relation?
[]
else
relation
=
join_dependency
.
apply_column_aliases
(
relation
)
...
...
activerecord/lib/active_record/scoping/named.rb
浏览文件 @
56b4fdb5
...
...
@@ -58,7 +58,7 @@ def default_scoped(scope = relation) # :nodoc:
end
def
default_extensions
# :nodoc:
if
scope
=
current_scope
||
build_default_scope
if
scope
=
scope_for_association
||
build_default_scope
scope
.
extensions
else
[]
...
...
activerecord/test/cases/scoping/relation_scoping_test.rb
浏览文件 @
56b4fdb5
...
...
@@ -421,6 +421,18 @@ def test_nested_scope_finder
end
end
def
test_none_scoping
Comment
.
none
.
scoping
do
assert_equal
2
,
@welcome
.
comments
.
count
assert_equal
"a comment..."
,
@welcome
.
comments
.
what_are_you
end
Comment
.
where
(
"1=1"
).
scoping
do
assert_equal
2
,
@welcome
.
comments
.
count
assert_equal
"a comment..."
,
@welcome
.
comments
.
what_are_you
end
end
def
test_should_maintain_default_scope_on_associations
magician
=
BadReference
.
find
(
1
)
assert_equal
[
magician
],
people
(
:michael
).
bad_references
...
...
@@ -461,4 +473,16 @@ def test_nested_scope_finder
assert_equal
"a category..."
,
@welcome
.
categories
.
what_are_you
end
end
def
test_none_scoping
Category
.
none
.
scoping
do
assert_equal
2
,
@welcome
.
categories
.
count
assert_equal
"a category..."
,
@welcome
.
categories
.
what_are_you
end
Category
.
where
(
"1=1"
).
scoping
do
assert_equal
2
,
@welcome
.
categories
.
count
assert_equal
"a category..."
,
@welcome
.
categories
.
what_are_you
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录