From 2e6760ea6ae5572311d4ab72b23d06d5e0ca8db8 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 9 May 2010 15:20:04 +0300 Subject: [PATCH 1/2] failing test for ticket 4562 - :select array not working in AR Signed-off-by: Santiago Pastorino --- activerecord/test/cases/method_scoping_test.rb | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/activerecord/test/cases/method_scoping_test.rb b/activerecord/test/cases/method_scoping_test.rb index a3b496a..6508181 100644 --- a/activerecord/test/cases/method_scoping_test.rb +++ b/activerecord/test/cases/method_scoping_test.rb @@ -72,6 +72,16 @@ class MethodScopingTest < ActiveRecord::TestCase def test_scoped_find_select Developer.send(:with_scope, :find => { :select => "id, name" }) do developer = Developer.find(:first, :conditions => "name = 'David'") + assert developer.has_attribute?(:id) + assert_equal "David", developer.name + assert !developer.has_attribute?(:salary) + end + end + + def test_scoped_find_select_using_array + Developer.send(:with_scope, :find => { :select => [:id, :name] }) do + developer = Developer.find(:first, :conditions => "name = 'David'") + assert developer.has_attribute?(:id) assert_equal "David", developer.name assert !developer.has_attribute?(:salary) end -- 1.7.1 From 9898b29538e2dddb8e8ae8afd35db12ba27e0e46 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 14 May 2010 14:51:21 -0300 Subject: [PATCH 2/2] :select array now works in AR [#4562 state:committed] --- .../lib/active_record/relation/query_methods.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 6782554..f5b307d 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -14,7 +14,7 @@ module ActiveRecord def #{query_method}(*args, &block) new_relation = clone new_relation.send(:apply_modules, Module.new(&block)) if block_given? - value = Array.wrap(args.flatten).reject {|x| x.blank? } + value = Array.wrap(#{query_method == :select ? "args" : "args.flatten"}).reject {|x| x.blank? } new_relation.#{query_method}_values += value if value.present? new_relation end -- 1.7.1