Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

activerecord sum returns a string?

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
like image 566
pingu Avatar asked Sep 28 '10 10:09

pingu


1 Answers

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?

like image 74
nfm Avatar answered Sep 26 '22 00:09

nfm