diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2011-07-26 06:33:54 -0700 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2011-07-26 06:33:54 -0700 |
commit | 89f3d8a886ee6d678b60b5e5df4d3a11d93c53d4 (patch) | |
tree | 6850321f2ca38c54eaffdff2f1c03ffcbad33684 /activerecord/lib | |
parent | cfd086a30298aef369d04a7d489d256699fef140 (diff) | |
parent | 04cc446d178653d362510e79a22db5300d463161 (diff) | |
download | rails-89f3d8a886ee6d678b60b5e5df4d3a11d93c53d4.tar.gz rails-89f3d8a886ee6d678b60b5e5df4d3a11d93c53d4.tar.bz2 rails-89f3d8a886ee6d678b60b5e5df4d3a11d93c53d4.zip |
Merge pull request #2271 from slawosz/enhance_select_method_api
allow select to have multiple arguments ie. Post.select(:id,:name,:author)
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index 1654ae1eac..792ffe1c5d 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -37,12 +37,15 @@ module ActiveRecord 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 |