aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2015-04-14 08:55:10 +0200
committerYves Senn <yves.senn@gmail.com>2015-04-14 08:57:10 +0200
commit524d40591eaa2f4d007409bfad386f6b107492eb (patch)
tree895292a4ad19660d86f7681360b0b77ac1484be7
parent34d3a6095100245283861ef480a54d0643bbee4c (diff)
parent50cae600bd6f4a8d1b437368c82f65bc118f8417 (diff)
downloadrails-524d40591eaa2f4d007409bfad386f6b107492eb.tar.gz
rails-524d40591eaa2f4d007409bfad386f6b107492eb.tar.bz2
rails-524d40591eaa2f4d007409bfad386f6b107492eb.zip
Merge pull request #19755 from yuki24/activerecord/support-for-set
Add support for Set to Relation#where
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb1
-rw-r--r--activerecord/test/cases/relations_test.rb10
3 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index 904ac5c26a..4d6be98d50 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Add support for `Set` to `Relation#where`.
+
+ *Yuki Nishijima*
+
* Fixed a bug where uniqueness validations would error on out of range values,
even if an validation should have prevented it from hitting the database.
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 43e9afe853..15b850c7f2 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -20,6 +20,7 @@ module ActiveRecord
register_handler(Range, RangeHandler.new(self))
register_handler(Relation, RelationHandler.new)
register_handler(Array, ArrayHandler.new(self))
+ register_handler(Set, ArrayHandler.new(self))
register_handler(AssociationQueryValue, AssociationQueryHandler.new(self))
end
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb
index 0cf44388fa..7886d9e504 100644
--- a/activerecord/test/cases/relations_test.rb
+++ b/activerecord/test/cases/relations_test.rb
@@ -848,6 +848,16 @@ class RelationTest < ActiveRecord::TestCase
}
end
+ def test_find_all_using_where_with_a_set
+ david = authors(:david)
+ mary = authors(:mary)
+ set = Set.new([david.id, mary.id])
+
+ assert_queries(1) {
+ assert_equal [david, mary], Author.where(id: set).to_a
+ }
+ end
+
def test_exists
davids = Author.where(:name => 'David')
assert davids.exists?