Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
844106ef
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,发现更多精彩内容 >>
提交
844106ef
编写于
5月 28, 2020
作者:
R
Ryuta Kamizono
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
`merge` doesn't allow to overwrite partially matching nodes
This makes `merge rewhere: true` follow the original `merge`'s behavior.
上级
817389d1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
5 deletion
+28
-5
activerecord/lib/active_record/relation/where_clause.rb
activerecord/lib/active_record/relation/where_clause.rb
+13
-5
activerecord/test/cases/relation/merging_test.rb
activerecord/test/cases/relation/merging_test.rb
+15
-0
未找到文件。
activerecord/lib/active_record/relation/where_clause.rb
浏览文件 @
844106ef
...
...
@@ -101,13 +101,12 @@ def contradiction?
end
def
extract_attributes
attrs
=
[]
predicates
.
each
do
|
node
|
Arel
.
fetch_attribute
(
node
)
{
|
attr
|
attrs
<<
attr
}
||
begin
attrs
<<
node
.
left
if
node
.
equality?
&&
node
.
left
.
is_a?
(
Arel
::
Predications
)
predicates
.
each_with_object
([])
do
|
node
,
attrs
|
attr
=
extract_attribute
(
node
)
||
begin
node
.
left
if
node
.
equality?
&&
node
.
left
.
is_a?
(
Arel
::
Predications
)
end
attrs
<<
attr
if
attr
end
attrs
end
protected
...
...
@@ -121,6 +120,15 @@ def referenced_columns
end
private
def
extract_attribute
(
node
)
attr_node
=
nil
Arel
.
fetch_attribute
(
node
)
do
|
attr
|
return
if
attr_node
&.!=
attr
# all attr nodes should be the same
attr_node
=
attr
end
attr_node
end
def
equalities
(
predicates
)
equalities
=
[]
...
...
activerecord/test/cases/relation/merging_test.rb
浏览文件 @
844106ef
...
...
@@ -36,6 +36,11 @@ def test_merge_in_clause
assert_equal
[
mary
,
bob
],
david_and_mary
.
merge
(
mary_and_bob
,
rewhere:
true
)
assert_equal
[
david
,
mary
],
mary_and_bob
.
merge
(
david_and_mary
,
rewhere:
true
)
david_and_bob
=
Author
.
where
(
id:
david
).
or
(
Author
.
where
(
name:
"Bob"
))
assert_equal
[
david
],
david_and_mary
.
merge
(
david_and_bob
)
assert_equal
[
david
],
david_and_mary
.
merge
(
david_and_bob
,
rewhere:
true
)
end
def
test_merge_between_clause
...
...
@@ -61,6 +66,11 @@ def test_merge_between_clause
assert_equal
[
mary
,
bob
],
david_and_mary
.
merge
(
mary_and_bob
,
rewhere:
true
)
assert_equal
[
david
,
mary
],
mary_and_bob
.
merge
(
david_and_mary
,
rewhere:
true
)
david_and_bob
=
Author
.
where
(
id:
david
).
or
(
Author
.
where
(
name:
"Bob"
))
assert_equal
[
david
],
david_and_mary
.
merge
(
david_and_bob
)
assert_equal
[
david
],
david_and_mary
.
merge
(
david_and_bob
,
rewhere:
true
)
end
def
test_merge_or_clause
...
...
@@ -86,6 +96,11 @@ def test_merge_or_clause
assert_equal
[
mary
,
bob
],
david_and_mary
.
merge
(
mary_and_bob
,
rewhere:
true
)
assert_equal
[
david
,
mary
],
mary_and_bob
.
merge
(
david_and_mary
,
rewhere:
true
)
david_and_bob
=
Author
.
where
(
id:
david
).
or
(
Author
.
where
(
name:
"Bob"
))
assert_equal
[
david
],
david_and_mary
.
merge
(
david_and_bob
)
assert_equal
[
david
],
david_and_mary
.
merge
(
david_and_bob
,
rewhere:
true
)
end
def
test_merge_not_in_clause
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录