From b0ab1a2c09769ba6e4351c1e059b1641ec51bc35 Mon Sep 17 00:00:00 2001 From: Rafael Magana Date: Sat, 20 Feb 2010 13:21:55 -0600 Subject: [PATCH] added :noselect option to ActiveRecord#find User.find(:noselect => "salt, crypted_password") --- activerecord/lib/active_record/base.rb | 20 +++++++++++++++----- 1 files changed, 15 insertions(+), 5 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 78c580f..3072b46 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -607,6 +607,7 @@ module ActiveRecord #:nodoc: def find(*args) options = args.extract_options! validate_find_options(options) + options = map_pseudo_options!(options) set_readonly_option!(options) case args.first @@ -616,7 +617,14 @@ module ActiveRecord #:nodoc: else find_from_ids(args, options) end end - + + def map_pseudo_options!(options) + if options[:noselect] + options[:select] = (column_names - options[:noselect].split(",").collect! { |c| c.strip }).join(",") + end + options + end + # A convenience wrapper for find(:first, *args). You can pass in all the # same arguments to this method as you can to find(:first). def first(*args) @@ -2223,7 +2231,7 @@ module ActiveRecord #:nodoc: end end end - + # Returns the class descending directly from ActiveRecord::Base or an # abstract class, if any, in the inheritance hierarchy. def class_of_active_record_descendant(klass) @@ -2403,7 +2411,9 @@ module ActiveRecord #:nodoc: expanded end - + + VALID_FIND_PSEUDO_OPTIONS = [:noselect] + def quote_bound_value(value) #:nodoc: if value.respond_to?(:map) && !value.acts_like?(:string) if value.respond_to?(:empty?) && value.empty? @@ -2426,9 +2436,9 @@ module ActiveRecord #:nodoc: :order, :select, :readonly, :group, :having, :from, :lock ] def validate_find_options(options) #:nodoc: - options.assert_valid_keys(VALID_FIND_OPTIONS) + options.assert_valid_keys(VALID_FIND_OPTIONS + VALID_FIND_PSEUDO_OPTIONS) end - + def set_readonly_option!(options) #:nodoc: # Inherit :readonly from finder scope if set. Otherwise, # if :joins is not blank then :readonly defaults to true. -- 1.6.4.2