Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
639a2e7c
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,发现更多精彩内容 >>
提交
639a2e7c
编写于
7月 31, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #16353 from eileencodes/refactor-join_keys-usage-in-reflection
Refactor join_keys to remove complex conditionals
上级
ddb0d4be
377bece6
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
29 deletion
+29
-29
activerecord/lib/active_record/associations/join_dependency/join_association.rb
...e_record/associations/join_dependency/join_association.rb
+3
-8
activerecord/lib/active_record/reflection.rb
activerecord/lib/active_record/reflection.rb
+26
-21
未找到文件。
activerecord/lib/active_record/associations/join_dependency/join_association.rb
浏览文件 @
639a2e7c
...
...
@@ -37,14 +37,9 @@ def join_constraints(foreign_table, foreign_klass, node, join_type, tables, scop
table
=
tables
.
shift
klass
=
reflection
.
klass
case
reflection
.
source_macro
when
:belongs_to
key
=
reflection
.
association_primary_key
foreign_key
=
reflection
.
foreign_key
else
key
=
reflection
.
foreign_key
foreign_key
=
reflection
.
active_record_primary_key
end
join_keys
=
reflection
.
join_keys
(
klass
)
key
=
join_keys
.
key
foreign_key
=
join_keys
.
foreign_key
constraint
=
build_constraint
(
klass
,
table
,
key
,
foreign_table
,
foreign_key
)
...
...
activerecord/lib/active_record/reflection.rb
浏览文件 @
639a2e7c
...
...
@@ -149,19 +149,10 @@ def class_name
JoinKeys
=
Struct
.
new
(
:key
,
:foreign_key
)
# :nodoc:
def
join_keys
(
assoc_klass
)
if
source_macro
==
:belongs_to
if
polymorphic?
reflection_key
=
association_primary_key
(
assoc_klass
)
else
reflection_key
=
association_primary_key
end
reflection_foreign_key
=
foreign_key
else
reflection_foreign_key
=
active_record_primary_key
reflection_key
=
foreign_key
end
JoinKeys
.
new
(
reflection_key
,
reflection_foreign_key
)
JoinKeys
.
new
(
foreign_key
,
active_record_primary_key
)
end
def
source_macro
;
macro
;
end
end
# Base class for AggregateReflection and AssociationReflection. Objects of
# AggregateReflection and AssociationReflection are returned by the Reflection::ClassMethods.
...
...
@@ -354,9 +345,8 @@ def check_preloadable!
end
alias
:check_eager_loadable!
:check_preloadable!
def
join_id_for
(
owner
)
#:nodoc:
key
=
(
source_macro
==
:belongs_to
)
?
foreign_key
:
active_record_primary_key
owner
[
key
]
def
join_id_for
(
owner
)
# :nodoc:
owner
[
active_record_primary_key
]
end
def
through_reflection
...
...
@@ -383,8 +373,6 @@ def scope_chain
scope
?
[[
scope
]]
:
[[]]
end
def
source_macro
;
macro
;
end
def
has_inverse?
inverse_name
end
...
...
@@ -574,7 +562,7 @@ def primary_key(klass)
end
end
class
HasManyReflection
<
AssociationReflection
#:nodoc:
class
HasManyReflection
<
AssociationReflection
#
:nodoc:
def
initialize
(
name
,
scope
,
options
,
active_record
)
super
(
name
,
scope
,
options
,
active_record
)
end
...
...
@@ -584,7 +572,7 @@ def macro; :has_many; end
def
collection?
;
true
;
end
end
class
HasOneReflection
<
AssociationReflection
#:nodoc:
class
HasOneReflection
<
AssociationReflection
#
:nodoc:
def
initialize
(
name
,
scope
,
options
,
active_record
)
super
(
name
,
scope
,
options
,
active_record
)
end
...
...
@@ -594,7 +582,7 @@ def macro; :has_one; end
def
has_one?
;
true
;
end
end
class
BelongsToReflection
<
AssociationReflection
#:nodoc:
class
BelongsToReflection
<
AssociationReflection
#
:nodoc:
def
initialize
(
name
,
scope
,
options
,
active_record
)
super
(
name
,
scope
,
options
,
active_record
)
end
...
...
@@ -602,9 +590,18 @@ def initialize(name, scope, options, active_record)
def
macro
;
:belongs_to
;
end
def
belongs_to?
;
true
;
end
def
join_keys
(
assoc_klass
)
key
=
polymorphic?
?
association_primary_key
(
assoc_klass
)
:
association_primary_key
JoinKeys
.
new
(
key
,
foreign_key
)
end
def
join_id_for
(
owner
)
# :nodoc:
owner
[
foreign_key
]
end
end
class
HasAndBelongsToManyReflection
<
AssociationReflection
#:nodoc:
class
HasAndBelongsToManyReflection
<
AssociationReflection
#
:nodoc:
def
initialize
(
name
,
scope
,
options
,
active_record
)
super
end
...
...
@@ -735,6 +732,10 @@ def scope_chain
end
end
def
join_keys
(
assoc_klass
)
source_reflection
.
join_keys
(
assoc_klass
)
end
# The macro used by the source association
def
source_macro
source_reflection
.
source_macro
...
...
@@ -802,6 +803,10 @@ def through_options
through_reflection
.
options
end
def
join_id_for
(
owner
)
# :nodoc:
source_reflection
.
join_id_for
(
owner
)
end
def
check_validity!
if
through_reflection
.
nil?
raise
HasManyThroughAssociationNotFoundError
.
new
(
active_record
.
name
,
self
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录