aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/relation
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-06-02 14:42:25 +0100
committerMikel Lindsaar <raasdnil@gmail.com>2010-06-03 23:32:12 +1000
commita9753637f4fcb68f65da96c85dfcb74ca1c13184 (patch)
tree7971b135e43f54b4b006730519bdf31da747e9c0 /activerecord/lib/active_record/relation
parent8aca1c09db1cb74a5b59aaa454fb7f551ccb6de0 (diff)
downloadrails-a9753637f4fcb68f65da96c85dfcb74ca1c13184.tar.gz
rails-a9753637f4fcb68f65da96c85dfcb74ca1c13184.tar.bz2
rails-a9753637f4fcb68f65da96c85dfcb74ca1c13184.zip
Special treatement for Relation#select { with block }
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index 6782554854..7a48a6596a 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -9,7 +9,7 @@ module ActiveRecord
(ActiveRecord::Relation::ASSOCIATION_METHODS + ActiveRecord::Relation::MULTI_VALUE_METHODS).each do |query_method|
attr_accessor :"#{query_method}_values"
- next if [:where, :having].include?(query_method)
+ next if [:where, :having, :select].include?(query_method)
class_eval <<-CEVAL, __FILE__, __LINE__ + 1
def #{query_method}(*args, &block)
new_relation = clone
@@ -21,6 +21,19 @@ module ActiveRecord
CEVAL
end
+ class_eval <<-CEVAL, __FILE__, __LINE__ + 1
+ def select(*args, &block)
+ if block_given?
+ to_a.select(&block)
+ else
+ new_relation = clone
+ value = Array.wrap(args.flatten).reject {|x| x.blank? }
+ new_relation.select_values += value if value.present?
+ new_relation
+ end
+ end
+ CEVAL
+
[:where, :having].each do |query_method|
class_eval <<-CEVAL, __FILE__, __LINE__ + 1
def #{query_method}(*args, &block)