Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e8be3a90
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,发现更多精彩内容 >>
未验证
提交
e8be3a90
编写于
1月 30, 2017
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix `scopes` implementation on `PolymorphicReflection`
`PolymorphicReflection` needs to be custom for handling scope lambdas
上级
4fef7c2a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
15 addition
and
54 deletion
+15
-54
activerecord/lib/active_record/associations/join_dependency.rb
...erecord/lib/active_record/associations/join_dependency.rb
+1
-1
activerecord/lib/active_record/associations/join_dependency/join_association.rb
...e_record/associations/join_dependency/join_association.rb
+2
-6
activerecord/lib/active_record/reflection.rb
activerecord/lib/active_record/reflection.rb
+12
-47
未找到文件。
activerecord/lib/active_record/associations/join_dependency.rb
浏览文件 @
e8be3a90
...
...
@@ -171,7 +171,7 @@ def make_constraints(parent, child, tables, join_type)
chain
=
child
.
reflection
.
chain
foreign_table
=
parent
.
table
foreign_klass
=
parent
.
base_klass
child
.
join_constraints
(
foreign_table
,
foreign_klass
,
child
,
join_type
,
tables
,
ch
ild
.
reflection
.
scope_chain
,
ch
ain
)
child
.
join_constraints
(
foreign_table
,
foreign_klass
,
child
,
join_type
,
tables
,
chain
)
end
def
make_outer_joins
(
parent
,
child
)
...
...
activerecord/lib/active_record/associations/join_dependency/join_association.rb
浏览文件 @
e8be3a90
...
...
@@ -23,14 +23,11 @@ def match?(other)
JoinInformation
=
Struct
.
new
:joins
,
:binds
def
join_constraints
(
foreign_table
,
foreign_klass
,
node
,
join_type
,
tables
,
scope_chain
,
chain
)
def
join_constraints
(
foreign_table
,
foreign_klass
,
node
,
join_type
,
tables
,
chain
)
joins
=
[]
binds
=
[]
tables
=
tables
.
reverse
scope_chain_index
=
0
scope_chain
=
scope_chain
.
reverse
# The chain starts with the target table, but we want to end with it here (makes
# more sense in this context), so we reverse
chain
.
reverse_each
do
|
reflection
|
...
...
@@ -44,7 +41,7 @@ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scop
constraint
=
build_constraint
(
klass
,
table
,
key
,
foreign_table
,
foreign_key
)
predicate_builder
=
PredicateBuilder
.
new
(
TableMetadata
.
new
(
klass
,
table
))
scope_chain_items
=
scope_chain
[
scope_chain_index
]
.
map
do
|
item
|
scope_chain_items
=
reflection
.
scopes
.
map
do
|
item
|
if
item
.
is_a?
(
Relation
)
item
else
...
...
@@ -52,7 +49,6 @@ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scop
.
instance_exec
(
node
,
&
item
)
end
end
scope_chain_index
+=
1
klass_scope
=
if
klass
.
current_scope
...
...
activerecord/lib/active_record/reflection.rb
浏览文件 @
e8be3a90
...
...
@@ -179,8 +179,12 @@ def scopes
scope
?
[
scope
]
:
[]
end
def
scope_chain
chain
.
map
(
&
:scopes
)
end
def
constraints
scope_chain
.
flatten
chain
.
map
(
&
:scopes
)
.
flatten
end
def
counter_cache_column
...
...
@@ -465,12 +469,6 @@ def nested?
false
end
# An array of arrays of scopes. Each item in the outside array corresponds to a reflection
# in the #chain.
def
scope_chain
scope
?
[[
scope
]]
:
[[]]
end
def
has_scope?
scope
end
...
...
@@ -820,30 +818,14 @@ def clear_association_scope_cache # :nodoc:
# but only Comment.tags will be represented in the #chain. So this method creates an array
# of scopes corresponding to the chain.
def
scopes
@sc
||=
if
scope
source_reflection
.
scopes
+
through_reflection
.
scopes
+
[
scope
]
if
scope
source_reflection
.
scopes
+
[
scope
]
else
source_reflection
.
scopes
+
through_reflection
.
scopes
end
return
@sc
scope_chain
=
source_reflection
.
scopes
scope_chain
=
through_reflection
.
scopes
# Add to it the scope from this reflection (if any)
scope_chain
.
first
<<
scope
if
scope
through_scope_chain
=
through_reflection
.
scope_chain
.
map
(
&
:dup
)
if
options
[
:source_type
]
through_scope_chain
.
first
<<
source_type_lambda
source_reflection
.
scopes
end
# Recursively fill out the rest of the array from the through reflection
scope_chain
+
through_scope_chain
end
def
source_type_
lambda
def
source_type_
scope
@source_type_lambda
||=
begin
type
=
foreign_type
source_type
=
options
[
:source_type
]
...
...
@@ -853,24 +835,6 @@ def source_type_lambda
end
end
def
scope_chain
@scope_chain
||=
begin
scope_chain
=
source_reflection
.
scope_chain
.
map
(
&
:dup
)
# Add to it the scope from this reflection (if any)
scope_chain
.
first
<<
scope
if
scope
through_scope_chain
=
through_reflection
.
scope_chain
.
map
(
&
:dup
)
if
options
[
:source_type
]
through_scope_chain
.
first
<<
source_type_lambda
end
# Recursively fill out the rest of the array from the through reflection
scope_chain
+
through_scope_chain
end
end
def
has_scope?
scope
||
options
[
:source_type
]
||
source_reflection
.
has_scope?
||
...
...
@@ -1043,10 +1007,11 @@ def initialize(reflection, previous_reflection)
end
def
scopes
scopes
=
@previous_reflection
.
scopes
if
@previous_reflection
.
options
[
:source_type
]
return
super
+
[
@previous_reflection
.
source_type_lambda
]
scopes
+
[
@previous_reflection
.
source_type_scope
]
else
return
super
scopes
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录