Skip to content

Commit 834e304

Browse files
committed
reverting where() functionality, adding a test
1 parent ecfb252 commit 834e304

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

activerecord/lib/active_record/relation/query_methods.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def joins(*args)
4747
clone.tap {|r| r.joins_values += args if args.present? }
4848
end
4949

50-
def where(opts, other = nil)
51-
value = build_where(opts, other)
50+
def where(opts, *rest)
51+
value = build_where(opts, rest)
5252
value ? clone.tap {|r| r.where_values += Array.wrap(value) } : clone
5353
end
5454

@@ -160,10 +160,10 @@ def build_arel
160160
arel
161161
end
162162

163-
def build_where(opts, other = nil)
163+
def build_where(opts, other = [])
164164
case opts
165165
when String, Array
166-
@klass.send(:sanitize_sql, other ? [opts, other] : opts)
166+
@klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))
167167
when Hash
168168
attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts)
169169
PredicateBuilder.new(table.engine).build_from_hash(attributes, table)

activerecord/test/cases/relations_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ def test_apply_relation_as_where_id
2222
assert_equal 5, Post.where(:id => post_authors).size
2323
end
2424

25+
def test_multivalue_where
26+
posts = Post.where('author_id = ? AND id = ?', 1, 1)
27+
assert_equal 1, posts.to_a.size
28+
end
29+
2530
def test_scoped
2631
topics = Topic.scoped
2732
assert_kind_of ActiveRecord::Relation, topics

0 commit comments

Comments
 (0)