Skip to content

Commit

Permalink
Reverting 16f6f25 (Change behaviour with empty array in where clause)
Browse files Browse the repository at this point in the history
  • Loading branch information
guilleiguaran committed Feb 8, 2013
1 parent 01e6731 commit fa987cb
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
5 changes: 0 additions & 5 deletions activerecord/CHANGELOG.md
@@ -1,10 +1,5 @@
## Rails 4.0.0 (unreleased) ##

* Raise `ArgumentError` instead of generating `column IN (NULL)` SQL when
empty array is used in where clause value.

*Roberto Miranda*

* Raise `ArgumentError` instead of generating invalid SQL when empty hash is
used in where clause value.

Expand Down
Expand Up @@ -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) unless records.empty?
scope.where! construct_join_attributes(*records)

case method
when :destroy
Expand Down
2 changes: 0 additions & 2 deletions activerecord/lib/active_record/relation/predicate_builder.rb
Expand Up @@ -17,8 +17,6 @@ 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

Expand Down
9 changes: 9 additions & 0 deletions activerecord/test/cases/finder_test.rb
Expand Up @@ -808,6 +808,15 @@ 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"',
Expand Down
4 changes: 1 addition & 3 deletions activerecord/test/cases/relation/where_test.rb
Expand Up @@ -98,9 +98,7 @@ def test_where_with_table_name_and_empty_hash
end

def test_where_with_table_name_and_empty_array
assert_raises(ArgumentError) do
Post.where(:id => [])
end
assert_equal 0, Post.where(:id => []).count
end

def test_where_with_empty_hash_and_no_foreign_key
Expand Down
5 changes: 2 additions & 3 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -515,9 +515,8 @@ def test_find_ids
end

def test_find_in_empty_array
assert_raises(ArgumentError) do
Author.all.where(:id => [])
end
authors = Author.all.where(:id => [])
assert authors.to_a.blank?
end

def test_where_with_ar_object
Expand Down

2 comments on commit fa987cb

@lexmag
Copy link
Contributor

@lexmag lexmag commented on fa987cb Feb 8, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be e170014 reverted?

@mdespuits
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you!

Please sign in to comment.