Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c81e4e6a
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,发现更多精彩内容 >>
提交
c81e4e6a
编写于
3月 27, 2014
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14154 from al2o3cr/issue12770
Pass a base relation to build_default_scope when joining
上级
dd3ea171
70a5e563
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
14 addition
and
4 deletion
+14
-4
activerecord/lib/active_record/associations/join_dependency/join_association.rb
...e_record/associations/join_dependency/join_association.rb
+1
-1
activerecord/lib/active_record/scoping/default.rb
activerecord/lib/active_record/scoping/default.rb
+3
-3
activerecord/test/cases/associations/inner_join_association_test.rb
...rd/test/cases/associations/inner_join_association_test.rb
+9
-0
activerecord/test/models/category.rb
activerecord/test/models/category.rb
+1
-0
未找到文件。
activerecord/lib/active_record/associations/join_dependency/join_association.rb
浏览文件 @
c81e4e6a
...
...
@@ -54,7 +54,7 @@ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scop
end
scope_chain_index
+=
1
scope_chain_items
.
concat
[
klass
.
send
(
:build_default_scope
)].
compact
scope_chain_items
.
concat
[
klass
.
send
(
:build_default_scope
,
ActiveRecord
::
Relation
.
create
(
klass
,
table
)
)].
compact
rel
=
scope_chain_items
.
inject
(
scope_chain_items
.
shift
)
do
|
left
,
right
|
left
.
merge
right
...
...
activerecord/lib/active_record/scoping/default.rb
浏览文件 @
c81e4e6a
...
...
@@ -94,14 +94,14 @@ def default_scope(scope = nil)
self
.
default_scopes
+=
[
scope
]
end
def
build_default_scope
# :nodoc:
def
build_default_scope
(
base_rel
=
relation
)
# :nodoc:
if
!
Base
.
is_a?
(
method
(
:default_scope
).
owner
)
# The user has defined their own default scope method, so call that
evaluate_default_scope
{
default_scope
}
elsif
default_scopes
.
any?
evaluate_default_scope
do
default_scopes
.
inject
(
relation
)
do
|
default_scope
,
scope
|
default_scope
.
merge
(
unscoped
{
scope
.
call
})
default_scopes
.
inject
(
base_rel
)
do
|
default_scope
,
scope
|
default_scope
.
merge
(
base_rel
.
scoping
{
scope
.
call
})
end
end
end
...
...
activerecord/test/cases/associations/inner_join_association_test.rb
浏览文件 @
c81e4e6a
...
...
@@ -117,4 +117,13 @@ def test_find_with_conditions_on_through_reflection
assert_equal
[
author
],
Author
.
where
(
id:
author
).
joins
(
:special_categorizations
)
end
test
"the default scope of the target is correctly aliased when joining associations"
do
author
=
Author
.
create!
name:
"Jon"
author
.
categories
.
create!
name:
'Not Special'
author
.
special_categories
.
create!
name:
'Special'
categories
=
author
.
categories
.
includes
(
:special_categorizations
).
references
(
:special_categorizations
).
to_a
assert_equal
2
,
categories
.
size
end
end
activerecord/test/models/category.rb
浏览文件 @
c81e4e6a
...
...
@@ -22,6 +22,7 @@ def self.what_are_you
end
has_many
:categorizations
has_many
:special_categorizations
has_many
:post_comments
,
:through
=>
:posts
,
:source
=>
:comments
has_many
:authors
,
:through
=>
:categorizations
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录