Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 9cf7e34
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
@@ -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.
Expand Down
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions activerecord/test/cases/relations_test.rb
Expand Up @@ -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")
Expand Down

0 comments on commit 9cf7e34

Please sign in to comment.