avatar

16

Renamed find_for to find_with, the conditions are now stackable

by abloke, 01 Feb, 2007 03:39 PM
12 16  
88 * Adjusted test schema and models
99 
1010 0.3 - 01-02-2007
11 * Added find_for and latest methods to ActivityLog
11 * Added find_for and latest methods to ActivityLog
12 
13 0.3.1 - 01-02-2007
14 * Renamed find_for to find_with, the conditions are now stackable
15 16  
4141   end
4242   
4343   # options are :culprit, :referenced, :activity_loggable, :limit
44   def self.find_for(options={})
44   def self.find_with(options={})
4545     limit = (options.delete(:limit) || 10)
4646     conditions = []
4747     conditions << self.send(:sanitize_sql, ["culprit_id = ?", options[:culprit]]) if options.keys.include? :culprit
4848     conditions << self.send(:sanitize_sql, ["referenced_id = ?", options[:referenced]]) if options.keys.include? :referenced
4949     conditions << self.send(:sanitize_sql, ["activity_loggable_id = ?", options[:activity_loggable]]) if options.keys.include? :activity_loggable
50     self.find(:all, :conditions => conditions, :limit => limit)
51   # rescue
52   #   raise "I couldn't run the find with the options you gave me"
50     self.find(:all, :conditions => conditions.join(" AND "), :limit => limit)
51   rescue
52     raise "I couldn't run the find with the options you gave me, sorry"
5353   end
5454 
5555 private