Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
2e7da54f
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,发现更多精彩内容 >>
提交
2e7da54f
编写于
12月 14, 2010
作者:
A
Aaron Patterson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
supporting arel AST nodes when building join statements
上级
6212ecaa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
18 deletion
+32
-18
activerecord/lib/active_record/associations/through_association_scope.rb
...b/active_record/associations/through_association_scope.rb
+17
-15
activerecord/lib/active_record/relation/query_methods.rb
activerecord/lib/active_record/relation/query_methods.rb
+15
-3
未找到文件。
activerecord/lib/active_record/associations/through_association_scope.rb
浏览文件 @
2e7da54f
...
...
@@ -55,33 +55,35 @@ def construct_select(custom_select = nil)
end
def
construct_joins
(
custom_joins
=
nil
)
polymorphic_join
=
nil
right
=
@reflection
.
through_reflection
.
klass
.
arel_table
left
=
@reflection
.
klass
.
arel_table
conditions
=
[]
if
@reflection
.
source_reflection
.
macro
==
:belongs_to
reflection_primary_key
=
@reflection
.
klass
.
primary_key
source_primary_key
=
@reflection
.
source_reflection
.
primary_key_name
if
@reflection
.
options
[
:source_type
]
polymorphic_join
=
"AND %s.%s = %s"
%
[
@reflection
.
through_reflection
.
quoted_table_name
,
"
#{
@reflection
.
source_reflection
.
options
[
:foreign_type
]
}
"
,
@owner
.
class
.
quote_value
(
@reflection
.
options
[
:source_type
])
]
column
=
@reflection
.
source_reflection
.
options
[
:foreign_type
]
conditions
<<
right
[
column
].
eq
(
@reflection
.
options
[
:source_type
])
end
else
reflection_primary_key
=
@reflection
.
source_reflection
.
primary_key_name
source_primary_key
=
@reflection
.
through_reflection
.
klass
.
primary_key
if
@reflection
.
source_reflection
.
options
[
:as
]
polymorphic_join
=
"AND %s.%s = %s"
%
[
@reflection
.
quoted_table_name
,
"
#{
@reflection
.
source_reflection
.
options
[
:as
]
}
_type"
,
@owner
.
class
.
quote_value
(
@reflection
.
through_reflection
.
klass
.
name
)
]
column
=
"
#{
@reflection
.
source_reflection
.
options
[
:as
]
}
_type"
conditions
<<
left
[
column
].
eq
(
@reflection
.
through_reflection
.
klass
.
name
)
end
end
"INNER JOIN %s ON %s.%s = %s.%s %s
#{
@reflection
.
options
[
:joins
]
}
#{
custom_joins
}
"
%
[
@reflection
.
through_reflection
.
quoted_table_name
,
@reflection
.
quoted_table_name
,
reflection_primary_key
,
@reflection
.
through_reflection
.
quoted_table_name
,
source_primary_key
,
polymorphic_join
]
conditions
<<
left
[
reflection_primary_key
].
eq
(
right
[
source_primary_key
])
right
.
create_join
(
right
,
right
.
create_on
(
right
.
create_and
(
conditions
)))
end
# Construct attributes for associate pointing to owner.
...
...
activerecord/lib/active_record/relation/query_methods.rb
浏览文件 @
2e7da54f
...
...
@@ -247,6 +247,8 @@ def build_joins(manager, joins)
'association_join'
when
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
::
JoinAssociation
'stashed_join'
when
Arel
::
Nodes
::
Join
'join_node'
else
raise
'unknown class: %s'
%
join
.
class
.
name
end
...
...
@@ -254,12 +256,22 @@ def build_joins(manager, joins)
association_joins
=
buckets
[
'association_join'
]
||
[]
stashed_association_joins
=
buckets
[
'stashed_join'
]
||
[]
join_nodes
=
buckets
[
'join_node'
]
||
[]
string_joins
=
(
buckets
[
'string_join'
]
||
[]).
map
{
|
x
|
x
.
strip
}.
uniq
join_list
=
custom_join_ast
(
manager
,
string_joins
)
join_dependency
=
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
.
new
(
@klass
,
association_joins
,
join_list
)
join_dependency
=
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
.
new
(
@klass
,
association_joins
,
join_list
)
join_nodes
.
each
do
|
join
|
join_dependency
.
table_aliases
[
join
.
left
.
name
.
downcase
]
=
1
end
join_dependency
.
graft
(
*
stashed_association_joins
)
...
...
@@ -270,9 +282,9 @@ def build_joins(manager, joins)
association
.
join_to
(
manager
)
end
return
manager
unless
join_list
manager
.
join_sources
.
concat
join_nodes
manager
.
join_sources
.
concat
join_list
join_list
.
each
{
|
j
|
manager
.
from
j
}
manager
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录