diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-26 12:57:34 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-26 12:57:34 +0530 |
commit | 187fbe5cbadf9d6fe5009a4a436fac28bcf8c99c (patch) | |
tree | ef880781f965fab4c0312fb41865d83ab75ec144 | |
parent | 5f5aa44d2de9e7d93087d52862502c12722bdae3 (diff) | |
download | rails-187fbe5cbadf9d6fe5009a4a436fac28bcf8c99c.tar.gz rails-187fbe5cbadf9d6fe5009a4a436fac28bcf8c99c.tar.bz2 rails-187fbe5cbadf9d6fe5009a4a436fac28bcf8c99c.zip |
Add support for multiple arguments to .where finder
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 1 |
2 files changed, 8 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 9aa45fb294..40ccdd4696 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -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 diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 529de4a6cf..50bd221bb3 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -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 |