Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
dbb6fa72
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,发现更多精彩内容 >>
提交
dbb6fa72
编写于
1月 24, 2011
作者:
J
Jon Leighton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't pass around conditions as strings in ThroughAssociation
上级
d85ee50e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
25 addition
and
30 deletion
+25
-30
activerecord/lib/active_record/associations/through_association.rb
...ord/lib/active_record/associations/through_association.rb
+25
-30
未找到文件。
activerecord/lib/active_record/associations/through_association.rb
浏览文件 @
dbb6fa72
...
...
@@ -3,13 +3,6 @@ module ActiveRecord
module
Associations
module
ThroughAssociation
def
conditions
@conditions
=
build_conditions
unless
defined?
(
@conditions
)
@conditions
end
alias_method
:sql_conditions
,
:conditions
protected
def
target_scope
...
...
@@ -17,7 +10,8 @@ def target_scope
end
def
association_scope
scope
=
super
.
joins
(
construct_joins
).
where
(
conditions
)
scope
=
super
.
joins
(
construct_joins
)
scope
=
add_conditions
(
scope
)
unless
@reflection
.
options
[
:include
]
scope
=
scope
.
includes
(
@reflection
.
source_reflection
.
options
[
:include
])
end
...
...
@@ -101,34 +95,35 @@ def construct_join_attributes(associate)
join_attributes
end
def
build_conditions
through_conditions
=
build_through_conditions
source_conditions
=
@reflection
.
source_reflection
.
options
[
:conditions
]
uses_sti
=
!
@reflection
.
through_reflection
.
klass
.
descends_from_active_record?
if
through_conditions
||
source_conditions
||
uses_sti
all
=
[]
all
<<
interpolate_sql
(
sanitize_sql
(
source_conditions
))
if
source_conditions
all
<<
through_conditions
if
through_conditions
all
<<
build_sti_condition
if
uses_sti
all
.
map
{
|
sql
|
"(
#{
sql
}
)"
}
*
' AND '
# The reason that we are operating directly on the scope here (rather than passing
# back some arel conditions to be added to the scope) is because scope.where([x, y])
# has a different meaning to scope.where(x).where(y) - the first version might
# perform some substitution if x is a string.
def
add_conditions
(
scope
)
unless
@reflection
.
through_reflection
.
klass
.
descends_from_active_record?
scope
=
scope
.
where
(
@reflection
.
through_reflection
.
klass
.
send
(
:type_condition
))
end
scope
=
scope
.
where
(
@reflection
.
source_reflection
.
options
[
:conditions
])
scope
.
where
(
through_conditions
)
end
def
build_through_conditions
# If there is a hash of conditions then we make sure the keys are scoped to the
# through table name if left ambiguous.
def
through_conditions
conditions
=
@reflection
.
through_reflection
.
options
[
:conditions
]
if
conditions
.
is_a?
(
Hash
)
interpolate_sql
(
@reflection
.
through_reflection
.
klass
.
send
(
:sanitize_sql
,
conditions
)).
gsub
(
@reflection
.
quoted_table_name
,
@reflection
.
through_reflection
.
quoted_table_name
)
elsif
conditions
interpolate_sql
(
sanitize_sql
(
conditions
))
end
end
Hash
[
conditions
.
map
{
|
key
,
value
|
unless
value
.
is_a?
(
Hash
)
||
key
.
to_s
.
include?
(
'.'
)
key
=
aliased_through_table
.
name
+
'.'
+
key
.
to_s
end
def
build_sti_condition
@reflection
.
through_reflection
.
klass
.
send
(
:type_condition
).
to_sql
[
key
,
value
]
}]
else
conditions
end
end
def
stale_state
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录