Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
85e1c4a0
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,发现更多精彩内容 >>
提交
85e1c4a0
编写于
2月 08, 2013
作者:
G
Guillermo Iguaran
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9216 from robertomiranda/where-with-empty-array
Activer Record: Change behaviour with empty array in where clause
上级
bcf0e08a
16f6f259
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
14 addition
and
13 deletion
+14
-13
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+5
-0
activerecord/lib/active_record/associations/has_many_through_association.rb
...ctive_record/associations/has_many_through_association.rb
+1
-1
activerecord/lib/active_record/relation/predicate_builder.rb
activerecord/lib/active_record/relation/predicate_builder.rb
+2
-0
activerecord/test/cases/finder_test.rb
activerecord/test/cases/finder_test.rb
+0
-9
activerecord/test/cases/relation/where_test.rb
activerecord/test/cases/relation/where_test.rb
+3
-1
activerecord/test/cases/relations_test.rb
activerecord/test/cases/relations_test.rb
+3
-2
未找到文件。
activerecord/CHANGELOG.md
浏览文件 @
85e1c4a0
## Rails 4.0.0 (unreleased) ##
*
Change behaviour with empty array in where clause,
the SQL generated when when were passed an empty array was insecure in some cases
Roberto Miranda
*
Raise ArgumentError instead of generate invalid SQL when empty hash is used in where clause value
Roberto Miranda
...
...
activerecord/lib/active_record/associations/has_many_through_association.rb
浏览文件 @
85e1c4a0
...
...
@@ -136,7 +136,7 @@ def delete_records(records, method)
records
=
load_target
if
records
==
:all
scope
=
through_association
.
scope
scope
.
where!
construct_join_attributes
(
*
records
)
scope
.
where!
construct_join_attributes
(
*
records
)
unless
records
.
empty?
case
method
when
:destroy
...
...
activerecord/lib/active_record/relation/predicate_builder.rb
浏览文件 @
85e1c4a0
...
...
@@ -17,6 +17,8 @@ def self.build_from_hash(klass, attributes, default_table)
queries
.
concat
expand
(
association
&&
association
.
klass
,
table
,
k
,
v
)
end
end
elsif
value
.
is_a?
(
Array
)
&&
value
.
empty?
raise
ArgumentError
,
"Condition value in SQL clause can't be an empty array"
else
column
=
column
.
to_s
...
...
activerecord/test/cases/finder_test.rb
浏览文件 @
85e1c4a0
...
...
@@ -808,15 +808,6 @@ def test_find_with_nil_inside_set_passed_for_one_attribute
assert_equal
[
2
,
1
].
sort
,
client_of
.
compact
.
sort
end
def
test_find_with_nil_inside_set_passed_for_attribute
client_of
=
Company
.
all
.
merge!
(
:where
=>
{
:client_of
=>
[
nil
]
},
:order
=>
'client_of DESC'
).
map
{
|
x
|
x
.
client_of
}
assert_equal
[],
client_of
.
compact
end
def
test_with_limiting_with_custom_select
posts
=
Post
.
references
(
:authors
).
merge
(
:includes
=>
:author
,
:select
=>
' posts.*, authors.id as "author_id"'
,
...
...
activerecord/test/cases/relation/where_test.rb
浏览文件 @
85e1c4a0
...
...
@@ -98,7 +98,9 @@ def test_where_with_table_name_and_empty_hash
end
def
test_where_with_table_name_and_empty_array
assert_equal
0
,
Post
.
where
(
:id
=>
[]).
count
assert_raises
(
ArgumentError
)
do
Post
.
where
(
:id
=>
[])
end
end
def
test_where_with_empty_hash_and_no_foreign_key
...
...
activerecord/test/cases/relations_test.rb
浏览文件 @
85e1c4a0
...
...
@@ -515,8 +515,9 @@ def test_find_ids
end
def
test_find_in_empty_array
authors
=
Author
.
all
.
where
(
:id
=>
[])
assert
authors
.
to_a
.
blank?
assert_raises
(
ArgumentError
)
do
Author
.
all
.
where
(
:id
=>
[])
end
end
def
test_where_with_ar_object
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录