Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 0.63 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class << ActiveRecord::Base
  2.  
  3.   # Model.find(:all, :except => 'body')
  4.   # except is a comma delimted list of fields to exclude from db queries
  5.  
  6.   def find_with_except(*args)
  7.     options = args.extract_options!
  8.     raise ArgumentError, "can't pass both :select and :except" if options[:except] && options[:select]
  9.     if options[:except]
  10.       formated_options = Array(options.delete(:except)).map!(&:to_s)
  11.       options[:select] = (Article.column_names - formated_options).join(", ")
  12.       find_without_except(*(args << options))
  13.     else
  14.       find_without_except(*(args << options))
  15.     end
  16.   end
  17.   alias_method_chain :find, :except
  18.  
  19. end