aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuillermo Iguaran <guilleiguaran@gmail.com>2013-02-08 14:22:10 -0500
committerGuillermo Iguaran <guilleiguaran@gmail.com>2013-02-08 14:22:10 -0500
commitfa987cb8ec4cc48018aac4949567823587155765 (patch)
treecc038c5d35b5cab62475dd793b546cd4f8959af5
parent01e67316d8c802df3928b53d0e0ce9153044f5ad (diff)
downloadrails-fa987cb8ec4cc48018aac4949567823587155765.tar.gz
rails-fa987cb8ec4cc48018aac4949567823587155765.tar.bz2
rails-fa987cb8ec4cc48018aac4949567823587155765.zip
Reverting 16f6f25 (Change behaviour with empty array in where clause)
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/associations/has_many_through_association.rb2
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb2
-rw-r--r--activerecord/test/cases/finder_test.rb9
-rw-r--r--activerecord/test/cases/relation/where_test.rb4
-rw-r--r--activerecord/test/cases/relations_test.rb5
6 files changed, 13 insertions, 14 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 69394c9f64..bd2f0eb0bc 100644
--- a/activerecord/CHANGELOG.md
+++ b/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.
diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb
index 2099effbeb..d1458f30ba 100644
--- a/activerecord/lib/active_record/associations/has_many_through_association.rb
+++ b/activerecord/lib/active_record/associations/has_many_through_association.rb
@@ -136,7 +136,7 @@ module ActiveRecord
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
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index db2588e725..24cbae83de 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -17,8 +17,6 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 683e4fbd97..a9fa107749 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -808,6 +808,15 @@ class FinderTest < ActiveRecord::TestCase
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"',
diff --git a/activerecord/test/cases/relation/where_test.rb b/activerecord/test/cases/relation/where_test.rb
index ccbfcc0549..8c8f4267a9 100644
--- a/activerecord/test/cases/relation/where_test.rb
+++ b/activerecord/test/cases/relation/where_test.rb
@@ -98,9 +98,7 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 981aa14e98..379c0c0758 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -515,9 +515,8 @@ class RelationTest < ActiveRecord::TestCase
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