diff --git a/lib/borrows_many/associations.rb b/lib/borrows_many/associations.rb index 70e57d9..1ed6c48 100644 --- a/lib/borrows_many/associations.rb +++ b/lib/borrows_many/associations.rb @@ -56,7 +56,7 @@ def count(*args) def calculate(operation, column_name, options = {}) - condtions = options.delete(:conditions) + conditions = options.delete(:conditions) options[:conditions] = "#{@reflection.quoted_link_table_name}.#{@reflection.join_key_name} = #{owner_quoted_id}" options[:conditions] << " AND (#{conditions})" if conditions @@ -66,6 +66,22 @@ def calculate(operation, column_name, options = {}) super(operation, column_name, options) end + def maximum(*args) + calculate(:max, *args) + end + + def minimum(*args) + calculate(:min, *args) + end + + def average(*args) + calculate(:avg, *args) + end + + def sum(*args) + calculate(:sum, *args) + end + def construct_sql @finder_sql = "#{@reflection.quoted_link_table_name}.#{@reflection.join_key_name} = #{owner_quoted_id}" @finder_sql << " AND (#{conditions})" if conditions @@ -86,4 +102,4 @@ def construct_join end end end -end \ No newline at end of file +end