Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
33a06829
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,发现更多精彩内容 >>
提交
33a06829
编写于
11月 25, 2014
作者:
S
Santiago Pastorino
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17754 from eileencodes/refactor-aliased_table_for
Combine aliased_table_for and aliased_name_for
上级
c310be0e
9e7037f1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
4 addition
and
13 deletion
+4
-13
activerecord/lib/active_record/associations/alias_tracker.rb
activerecord/lib/active_record/associations/alias_tracker.rb
+3
-12
activerecord/lib/active_record/associations/join_dependency.rb
...erecord/lib/active_record/associations/join_dependency.rb
+1
-1
未找到文件。
activerecord/lib/active_record/associations/alias_tracker.rb
浏览文件 @
33a06829
...
...
@@ -57,20 +57,10 @@ def initialize(connection, aliases)
end
def
aliased_table_for
(
table_name
,
aliased_name
)
table_alias
=
aliased_name_for
(
table_name
,
aliased_name
)
if
table_alias
==
table_name
Arel
::
Table
.
new
(
table_name
)
else
Arel
::
Table
.
new
(
table_name
).
alias
(
table_alias
)
end
end
def
aliased_name_for
(
table_name
,
aliased_name
)
if
aliases
[
table_name
].
zero?
# If it's zero, we can have our table_name
aliases
[
table_name
]
=
1
table_name
Arel
::
Table
.
new
(
table_name
)
else
# Otherwise, we need to use an alias
aliased_name
=
connection
.
table_alias_for
(
aliased_name
)
...
...
@@ -78,11 +68,12 @@ def aliased_name_for(table_name, aliased_name)
# Update the count
aliases
[
aliased_name
]
+=
1
if
aliases
[
aliased_name
]
>
1
table_alias
=
if
aliases
[
aliased_name
]
>
1
"
#{
truncate
(
aliased_name
)
}
_
#{
aliases
[
aliased_name
]
}
"
else
aliased_name
end
Arel
::
Table
.
new
(
table_name
).
alias
(
table_alias
)
end
end
...
...
activerecord/lib/active_record/associations/join_dependency.rb
浏览文件 @
33a06829
...
...
@@ -94,7 +94,7 @@ def self.walk_tree(associations, hash)
#
def
initialize
(
base
,
associations
,
joins
)
@alias_tracker
=
AliasTracker
.
create
(
base
.
connection
,
joins
)
@alias_tracker
.
aliased_
nam
e_for
(
base
.
table_name
,
base
.
table_name
)
# Updates the count for base.table_name to 1
@alias_tracker
.
aliased_
tabl
e_for
(
base
.
table_name
,
base
.
table_name
)
# Updates the count for base.table_name to 1
tree
=
self
.
class
.
make_tree
associations
@join_root
=
JoinBase
.
new
base
,
build
(
tree
,
base
)
@join_root
.
children
.
each
{
|
child
|
construct_tables!
@join_root
,
child
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录