Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11550 (closed defect: fixed)

Opened 8 months ago

Last modified 8 months ago

[PATCH] Calculations sum should default to 0 when options causes model to return nothing

Reported by: kamal Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords: tiny
Cc:

Description

That's a bad title. It is better illustrated below:

Account.sum(:balance, :conditions => '1 = 2')

should return 0. Currently, it returns nil.

Attachments

calculations_sum_should_default_to_zero.patch (1.3 kB) - added by kamal on 04/08/08 01:06:18.
patch and test

Change History

04/08/08 01:06:18 changed by kamal

  • attachment calculations_sum_should_default_to_zero.patch added.

patch and test

04/08/08 05:20:38 changed by rick

  • status changed from new to closed.
  • resolution set to fixed.

(In [9243]) ActiveRecord::Base#sum defaults to 0 if no rows are returned. Closes #11550 [kamal]