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

Ticket #8041 (new defect)

Opened 3 years ago

Last modified 2 years ago

[PATCH] Decimal With Zero Scale Is Converted To Integer

Reported by: sethladd Assigned to: core
Priority: normal Milestone: 2.1
Component: ActiveRecord Version: edge
Severity: major Keywords:
Cc: aeden

Description

A decimal type with a scale of zero is converted into an integer type, inside of schema_definitions.rb. This is completely counter intuitive, and certainly violates the "Principle of Least Surprise".

Suggest leaving decimal as a decimal, regardless of its scale.

Specifically, this is in the simplified_type method in schema_definitions.rb, at or around line 180.

Attachments

make_decimals_decimal.diff (2.1 kB) - added by wycats on 06/18/07 01:44:48.

Change History

04/10/07 03:21:19 changed by sethladd

This is actually a big deal, because Rails doesn't support bigint out of the box. So the only way to get a supported concept of a large number is to use decimal, since it's converted to BigDecimal in Rails. However, many times you just need a large integer, so having a scale of zero makes a lot of sense.

So, either support bigint formally, or allow a decimal type with a zero scale.

It seems really silly to force me to do this: decimal(18,1) when all I want to say is decimal(18,0). (of course, bigint is a better choice here, but that's another issue)

04/10/07 10:57:44 changed by aeden

  • cc set to aeden.

06/16/07 23:56:11 changed by wycats

Is there any objection to just making this decimal in both cases?

06/18/07 01:44:35 changed by wycats

I've attached a patch that makes decimals always decimal, along with small modifications to the applicable unit tests.

06/18/07 01:44:48 changed by wycats

  • attachment make_decimals_decimal.diff added.

06/18/07 01:45:22 changed by wycats

  • summary changed from Decimal With Zero Scale Is Converted To Integer to [PATCH] Decimal With Zero Scale Is Converted To Integer.

04/08/08 17:51:02 changed by chrisrbailey

  • milestone changed from 1.2.7 to 2.1.

Just updating to state that this is still a problem in Rails 2.0.2/Edge 9170, thus updating the Milestone to 2.1.

05/28/08 08:32:20 changed by evan

+1