Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c02fd2ac
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 搜索 >>
提交
c02fd2ac
编写于
12月 14, 2010
作者:
A
Aaron Patterson
提交者:
Vijay Dev
12月 16, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
taking advantage of the JoinSource node in the SQL AST
上级
08ccca76
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
14 addition
and
32 deletion
+14
-32
activerecord/lib/active_record/associations/class_methods/join_dependency.rb
...tive_record/associations/class_methods/join_dependency.rb
+6
-14
activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb
...iations/class_methods/join_dependency/join_association.rb
+0
-1
activerecord/lib/active_record/relation/finder_methods.rb
activerecord/lib/active_record/relation/finder_methods.rb
+1
-1
activerecord/lib/active_record/relation/query_methods.rb
activerecord/lib/active_record/relation/query_methods.rb
+7
-16
未找到文件。
activerecord/lib/active_record/associations/class_methods/join_dependency.rb
浏览文件 @
c02fd2ac
...
...
@@ -47,24 +47,16 @@ def columns
end
def
count_aliases_from_table_joins
(
name
)
return
0
if
!
@table_joins
||
Arel
::
Table
===
@table_joins
return
0
if
Arel
::
Table
===
@table_joins
# quoted_name should be downcased as some database adapters (Oracle) return quoted name in uppercase
quoted_name
=
active_record
.
connection
.
quote_table_name
(
name
).
downcase
@table_joins
.
grep
(
Arel
::
Nodes
::
Join
).
map
{
|
join
|
right
=
join
.
right
case
right
when
Arel
::
Table
right
.
name
.
downcase
==
name
?
1
:
0
when
String
# Table names + table aliases
right
.
downcase
.
scan
(
/join(?:\s+\w+)?\s+(\S+\s+)?
#{
quoted_name
}
\son/
).
size
else
0
end
@table_joins
.
map
{
|
join
|
# Table names + table aliases
join
.
left
.
downcase
.
scan
(
/join(?:\s+\w+)?\s+(\S+\s+)?
#{
quoted_name
}
\son/
).
size
}.
sum
end
...
...
activerecord/lib/active_record/associations/class_methods/join_dependency/join_association.rb
浏览文件 @
c02fd2ac
...
...
@@ -138,7 +138,6 @@ def join_target_table(relation, condition)
ands
=
relation
.
create_and
(
conditions
)
join
=
relation
.
create_join
(
relation
.
froms
.
first
,
target_table
,
relation
.
create_on
(
ands
),
join_type
)
...
...
activerecord/lib/active_record/relation/finder_methods.rb
浏览文件 @
c02fd2ac
...
...
@@ -187,7 +187,7 @@ def exists?(id = nil)
def
find_with_associations
including
=
(
@eager_load_values
+
@includes_values
).
uniq
join_dependency
=
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
.
new
(
@klass
,
including
,
nil
)
join_dependency
=
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
.
new
(
@klass
,
including
,
[]
)
rows
=
construct_relation_for_association_find
(
join_dependency
).
to_a
join_dependency
.
instantiate
(
rows
)
rescue
ThrowResult
...
...
activerecord/lib/active_record/relation/query_methods.rb
浏览文件 @
c02fd2ac
...
...
@@ -191,27 +191,19 @@ def build_arel
def
custom_join_ast
(
table
,
joins
)
joins
=
joins
.
reject
{
|
join
|
join
.
blank?
}
return
if
joins
.
empty?
return
[]
if
joins
.
empty?
@implicit_readonly
=
true
joins
.
map
!
do
|
join
|
joins
.
map
do
|
join
|
case
join
when
Array
join
=
Arel
.
sql
(
join
.
join
(
' '
))
if
array_of_strings?
(
join
)
when
String
join
=
Arel
.
sql
(
join
)
end
join
table
.
create_string_join
(
join
)
end
head
=
table
.
create_string_join
(
table
,
joins
.
shift
)
joins
.
inject
(
head
)
do
|
ast
,
join
|
ast
.
right
=
table
.
create_string_join
(
ast
.
right
,
join
)
end
head
end
def
collapse_wheres
(
arel
,
wheres
)
...
...
@@ -256,9 +248,9 @@ def build_joins(manager, joins)
stashed_association_joins
=
joins
.
grep
(
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
::
JoinAssociation
)
non_association_joins
=
(
joins
-
association_joins
-
stashed_association_joins
)
join_
ast
=
custom_join_ast
(
manager
.
froms
.
first
,
non_association_joins
)
join_
list
=
custom_join_ast
(
manager
,
non_association_joins
)
join_dependency
=
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
.
new
(
@klass
,
association_joins
,
join_
a
st
)
join_dependency
=
ActiveRecord
::
Associations
::
ClassMethods
::
JoinDependency
.
new
(
@klass
,
association_joins
,
join_
li
st
)
join_dependency
.
graft
(
*
stashed_association_joins
)
...
...
@@ -269,10 +261,9 @@ def build_joins(manager, joins)
association
.
join_to
(
manager
)
end
return
manager
unless
join_
a
st
return
manager
unless
join_
li
st
join_ast
.
left
=
manager
.
froms
.
first
manager
.
from
join_ast
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录