Permalink
Browse files

Treat `Set` as an `Array` in `Relation#where`

I do not want to set the expectation that any enumerable object should
behave this way, but this case in particular comes up frequently enough
that I'm caving on this one.

Fixes #30684.
  • Loading branch information...
sgrif committed Sep 26, 2017
1 parent 7352f8d commit 9cf7e3494f5bd34f1382c1ff4ea3d811a4972ae2
@@ -1,3 +1,8 @@
* Passing a `Set` to `Relation#where` now behaves the same as passing an
array.
*Sean Griffin*
* Use given algorithm while removing index from database.
Fixes #24190.
@@ -13,6 +13,7 @@ def initialize(table)
register_handler(Range, RangeHandler.new(self))
register_handler(Relation, RelationHandler.new)
register_handler(Array, ArrayHandler.new(self))
register_handler(Set, ArrayHandler.new(self))
end
def build_from_hash(attributes)
@@ -1912,6 +1912,19 @@ def test_relation_join_method
end
end
test "#where with set" do
david = authors(:david)
mary = authors(:mary)
authors = Author.where(name: ["David", "Mary"].to_set)
assert_equal [david, mary], authors
end
test "#where with empty set" do
authors = Author.where(name: Set.new)
assert_empty authors
end
private
def custom_post_relation
table_alias = Post.arel_table.alias("omg_posts")

0 comments on commit 9cf7e34

Please sign in to comment.