1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add support for multiple arguments to .where finder

This commit is contained in:
Pratik Naik 2009-12-26 12:57:34 +05:30
parent 5f5aa44d2d
commit 187fbe5cba
2 changed files with 8 additions and 2 deletions

View file

@ -98,8 +98,13 @@ module ActiveRecord
create_new_relation(join)
end
def where(conditions)
conditions = @klass.send(:merge_conditions, conditions) if [String, Hash, Array].include?(conditions.class)
def where(*args)
if [String, Hash, Array].include?(args.first.class)
conditions = @klass.send(:merge_conditions, args.size > 1 ? Array.wrap(args) : args.first)
else
conditions = args.first
end
create_new_relation(@relation.where(conditions))
end

View file

@ -27,6 +27,7 @@ class RelationTest < ActiveRecord::TestCase
def test_finding_with_conditions
assert_equal ["David"], Author.where(:name => 'David').map(&:name)
assert_equal ['Mary'], Author.where(["name = ?", 'Mary']).map(&:name)
assert_equal ['Mary'], Author.where("name = ?", 'Mary').map(&:name)
end
def test_finding_with_order