diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-30 14:12:01 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-07-30 14:12:01 -0700 |
commit | 834e304b223723d63596034ef338d9af6655d35b (patch) | |
tree | 68d923622ba25e83988069b6bc273d7ca7489796 | |
parent | ecfb252e7a99bac6569f744064ef7f1ee1b31556 (diff) | |
download | rails-834e304b223723d63596034ef338d9af6655d35b.tar.gz rails-834e304b223723d63596034ef338d9af6655d35b.tar.bz2 rails-834e304b223723d63596034ef338d9af6655d35b.zip |
reverting where() functionality, adding a test
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 5 |
2 files changed, 9 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index b941231a65..a92d180442 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -47,8 +47,8 @@ module ActiveRecord clone.tap {|r| r.joins_values += args if args.present? } end - def where(opts, other = nil) - value = build_where(opts, other) + def where(opts, *rest) + value = build_where(opts, rest) value ? clone.tap {|r| r.where_values += Array.wrap(value) } : clone end @@ -160,10 +160,10 @@ module ActiveRecord arel end - def build_where(opts, other = nil) + def build_where(opts, other = []) case opts when String, Array - @klass.send(:sanitize_sql, other ? [opts, other] : opts) + @klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other)) when Hash attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts) PredicateBuilder.new(table.engine).build_from_hash(attributes, table) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index cb252d56fe..c9313fe7b6 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -22,6 +22,11 @@ class RelationTest < ActiveRecord::TestCase assert_equal 5, Post.where(:id => post_authors).size end + def test_multivalue_where + posts = Post.where('author_id = ? AND id = ?', 1, 1) + assert_equal 1, posts.to_a.size + end + def test_scoped topics = Topic.scoped assert_kind_of ActiveRecord::Relation, topics |