lib/mongoid/finders.rb in mongoid-0.11.7 vs lib/mongoid/finders.rb in mongoid-0.11.8

- old
+ new

@@ -74,10 +74,25 @@ # <tt>Person.last(:conditions => { :attribute => "value" })</tt> def last(*args) find(:last, *args) end + # Convenience method for returning the max value of a field. + # + # Options: + # + # field: The field to use when calculating the max. + # + # Example: + # + # <tt>Person.max(:age)</tt> + # + # Returns: <tt>Float</tt> max value. + def max(field) + Criteria.new(self).max(field) + end + # Will execute a +Criteria+ based on the +DynamicFinder+ that gets # generated. # # Options: # @@ -90,9 +105,24 @@ def method_missing(name, *args) dyna = DynamicFinder.new(name, *args) finder, conditions = dyna.finder, dyna.conditions results = find(finder, :conditions => conditions) results ? results : dyna.create(self) + end + + # Convenience method for returning the min value of a field. + # + # Options: + # + # field: The field to use when calculating the min. + # + # Example: + # + # <tt>Person.min(:age)</tt> + # + # Returns: <tt>Float</tt> min value. + def min(field) + Criteria.new(self).min(field) end # Find all documents in paginated fashion given the supplied arguments. # If no parameters are passed just default to offset 0 and limit 20. #