views:

29

answers:

1

This seems very strange to me, an active record sum returns a string, not a number

basket_items.sum("price")

This seems to make it work, but i thought i may have missed something, as this seems like very strange behaviour.

basket_items.sum("price").to_i
+2  A: 

According to the (rails 2.3.9) API:

The value is returned with the same data type of the column, 0 if there’s no row

Could your price column be a string or text?

nfm
It is possible though that the database is sqlite3 in which case everything is stored as a string which might be causing the issue. I don't experience the problem on mysql but don't have sqlite3 to test against at the moment.
Shadwell
Using mysql, and my price column is a float, using Rails 2.3.9
pingu