Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
fbd917f5
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,发现更多精彩内容 >>
提交
fbd917f5
编写于
2月 10, 2011
作者:
E
Ernie Miller
提交者:
Aaron Patterson
2月 12, 2011
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove Relation#& alias for Relation#merge
上级
7eb554bd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
12 addition
and
14 deletion
+12
-14
activerecord/lib/active_record/associations/association_proxy.rb
...ecord/lib/active_record/associations/association_proxy.rb
+1
-1
activerecord/lib/active_record/associations/through_association.rb
...ord/lib/active_record/associations/through_association.rb
+1
-1
activerecord/lib/active_record/relation/spawn_methods.rb
activerecord/lib/active_record/relation/spawn_methods.rb
+0
-2
activerecord/test/cases/method_scoping_test.rb
activerecord/test/cases/method_scoping_test.rb
+1
-1
activerecord/test/cases/relation_scoping_test.rb
activerecord/test/cases/relation_scoping_test.rb
+2
-2
activerecord/test/cases/relations_test.rb
activerecord/test/cases/relations_test.rb
+7
-7
未找到文件。
activerecord/lib/active_record/associations/association_proxy.rb
浏览文件 @
fbd917f5
...
@@ -166,7 +166,7 @@ def send(method, *args)
...
@@ -166,7 +166,7 @@ def send(method, *args)
end
end
def
scoped
def
scoped
target_scope
&
@association_scope
target_scope
.
merge
(
@association_scope
)
end
end
protected
protected
...
...
activerecord/lib/active_record/associations/through_association.rb
浏览文件 @
fbd917f5
...
@@ -6,7 +6,7 @@ module ThroughAssociation
...
@@ -6,7 +6,7 @@ module ThroughAssociation
protected
protected
def
target_scope
def
target_scope
super
&
@reflection
.
through_reflection
.
klass
.
scoped
super
.
merge
(
@reflection
.
through_reflection
.
klass
.
scoped
)
end
end
def
association_scope
def
association_scope
...
...
activerecord/lib/active_record/relation/spawn_methods.rb
浏览文件 @
fbd917f5
...
@@ -61,8 +61,6 @@ def merge(r)
...
@@ -61,8 +61,6 @@ def merge(r)
merged_relation
merged_relation
end
end
alias
:&
:merge
# Removes from the query the condition(s) specified in +skips+.
# Removes from the query the condition(s) specified in +skips+.
#
#
# Example:
# Example:
...
...
activerecord/test/cases/method_scoping_test.rb
浏览文件 @
fbd917f5
...
@@ -227,7 +227,7 @@ def test_scoped_create
...
@@ -227,7 +227,7 @@ def test_scoped_create
end
end
def
test_scoped_create_with_join_and_merge
def
test_scoped_create_with_join_and_merge
(
Comment
.
where
(
:body
=>
"but Who's Buying?"
).
joins
(
:post
)
&
Post
.
where
(
:body
=>
'Peace Sells...'
)).
with_scope
do
Comment
.
where
(
:body
=>
"but Who's Buying?"
).
joins
(
:post
).
merge
(
Post
.
where
(
:body
=>
'Peace Sells...'
)).
with_scope
do
assert_equal
({
:body
=>
"but Who's Buying?"
},
Comment
.
scoped
.
scope_for_create
)
assert_equal
({
:body
=>
"but Who's Buying?"
},
Comment
.
scoped
.
scope_for_create
)
end
end
end
end
...
...
activerecord/test/cases/relation_scoping_test.rb
浏览文件 @
fbd917f5
...
@@ -488,8 +488,8 @@ def test_scope_composed_by_limit_and_then_offset_is_equal_to_scope_composed_by_o
...
@@ -488,8 +488,8 @@ def test_scope_composed_by_limit_and_then_offset_is_equal_to_scope_composed_by_o
end
end
def
test_create_with_merge
def
test_create_with_merge
aaron
=
(
PoorDeveloperCalledJamis
.
create_with
(
:name
=>
'foo'
,
:salary
=>
20
)
&
aaron
=
PoorDeveloperCalledJamis
.
create_with
(
:name
=>
'foo'
,
:salary
=>
20
).
merge
(
PoorDeveloperCalledJamis
.
create_with
(
:name
=>
'Aaron'
)).
new
PoorDeveloperCalledJamis
.
create_with
(
:name
=>
'Aaron'
)).
new
assert_equal
20
,
aaron
.
salary
assert_equal
20
,
aaron
.
salary
assert_equal
'Aaron'
,
aaron
.
name
assert_equal
'Aaron'
,
aaron
.
name
...
...
activerecord/test/cases/relations_test.rb
浏览文件 @
fbd917f5
...
@@ -545,17 +545,17 @@ def test_select_argument_error
...
@@ -545,17 +545,17 @@ def test_select_argument_error
end
end
def
test_relation_merging
def
test_relation_merging
devs
=
Developer
.
where
(
"salary >= 80000"
)
&
Developer
.
limit
(
2
)
&
Developer
.
order
(
'id ASC'
).
where
(
"id < 3"
)
devs
=
Developer
.
where
(
"salary >= 80000"
)
.
merge
(
Developer
.
limit
(
2
)).
merge
(
Developer
.
order
(
'id ASC'
).
where
(
"id < 3"
)
)
assert_equal
[
developers
(
:david
),
developers
(
:jamis
)],
devs
.
to_a
assert_equal
[
developers
(
:david
),
developers
(
:jamis
)],
devs
.
to_a
dev_with_count
=
Developer
.
limit
(
1
)
&
Developer
.
order
(
'id DESC'
)
&
Developer
.
select
(
'developers.*'
)
dev_with_count
=
Developer
.
limit
(
1
)
.
merge
(
Developer
.
order
(
'id DESC'
)).
merge
(
Developer
.
select
(
'developers.*'
)
)
assert_equal
[
developers
(
:poor_jamis
)],
dev_with_count
.
to_a
assert_equal
[
developers
(
:poor_jamis
)],
dev_with_count
.
to_a
end
end
def
test_relation_merging_with_eager_load
def
test_relation_merging_with_eager_load
relations
=
[]
relations
=
[]
relations
<<
(
Post
.
order
(
'comments.id DESC'
)
&
Post
.
eager_load
(
:last_comment
)
&
Post
.
scoped
)
relations
<<
Post
.
order
(
'comments.id DESC'
).
merge
(
Post
.
eager_load
(
:last_comment
)).
merge
(
Post
.
scoped
)
relations
<<
(
Post
.
eager_load
(
:last_comment
)
&
Post
.
order
(
'comments.id DESC'
)
&
Post
.
scoped
)
relations
<<
Post
.
eager_load
(
:last_comment
).
merge
(
Post
.
order
(
'comments.id DESC'
)).
merge
(
Post
.
scoped
)
relations
.
each
do
|
posts
|
relations
.
each
do
|
posts
|
post
=
posts
.
find
{
|
p
|
p
.
id
==
1
}
post
=
posts
.
find
{
|
p
|
p
.
id
==
1
}
...
@@ -564,18 +564,18 @@ def test_relation_merging_with_eager_load
...
@@ -564,18 +564,18 @@ def test_relation_merging_with_eager_load
end
end
def
test_relation_merging_with_locks
def
test_relation_merging_with_locks
devs
=
Developer
.
lock
.
where
(
"salary >= 80000"
).
order
(
"id DESC"
)
&
Developer
.
limit
(
2
)
devs
=
Developer
.
lock
.
where
(
"salary >= 80000"
).
order
(
"id DESC"
)
.
merge
(
Developer
.
limit
(
2
)
)
assert_present
devs
.
locked
assert_present
devs
.
locked
end
end
def
test_relation_merging_with_preload
def
test_relation_merging_with_preload
[
Post
.
scoped
&
Post
.
preload
(
:author
),
Post
.
preload
(
:author
)
&
Post
.
scoped
].
each
do
|
posts
|
[
Post
.
scoped
.
merge
(
Post
.
preload
(
:author
)),
Post
.
preload
(
:author
).
merge
(
Post
.
scoped
)
].
each
do
|
posts
|
assert_queries
(
2
)
{
assert
posts
.
first
.
author
}
assert_queries
(
2
)
{
assert
posts
.
first
.
author
}
end
end
end
end
def
test_relation_merging_with_joins
def
test_relation_merging_with_joins
comments
=
Comment
.
joins
(
:post
).
where
(
:body
=>
'Thank you for the welcome'
)
&
Post
.
where
(
:body
=>
'Such a lovely day'
)
comments
=
Comment
.
joins
(
:post
).
where
(
:body
=>
'Thank you for the welcome'
)
.
merge
(
Post
.
where
(
:body
=>
'Such a lovely day'
)
)
assert_equal
1
,
comments
.
count
assert_equal
1
,
comments
.
count
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录