Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow select to have multiple arguments

  • Loading branch information...
commit 04cc446d178653d362510e79a22db5300d463161 1 parent 8e00611
@slawosz slawosz authored slawosz committed
View
9 activerecord/lib/active_record/relation/query_methods.rb
@@ -37,12 +37,15 @@ def preload(*args)
relation
end
- def select(value = Proc.new)
+ def select(*args, &blk)
+ if !block_given? && args.blank?
+ raise ArgumentError
+ end
if block_given?
- to_a.select {|*block_args| value.call(*block_args) }
+ to_a.select {|*block_args| blk.call(*block_args) }
else
relation = clone
- relation.select_values += Array.wrap(value)
+ relation.select_values += args
relation
end
end
View
5 activerecord/test/cases/base_test.rb
@@ -123,6 +123,11 @@ def test_select_symbol
assert_equal Topic.all.map(&:id).sort, topic_ids
end
+ def test_select_symbol_for_many_arguments
+ topics = Topic.select(:id, :author_name).map{|topic| [topic.id, topic.author_name]}.sort
+ assert_equal Topic.all.map{|topic| [topic.id,topic.author_name]}.sort, topics
+ end
+
def test_table_exists
assert !NonExistentTable.table_exists?
assert Topic.table_exists?
Please sign in to comment.
Something went wrong with that request. Please try again.