This project is archived and is in readonly mode.
ActiveRecord::Dirty incorrect behaviour
Reported by Ben Symonds | December 8th, 2008 @ 02:26 PM | in 2.x
With nullable integer column, field_changed? method returns true when attribute changed from 0 to '0'. Should return false.
The field_changed? method does some funny stuff with nullable integer columns. 0 and '' (empty string) are different, but '' will typecast to integer 0 so will not appear as a changed. So instead of typecasting, '' is just manually converted to nil.
Problem occurs when old value is 0, but new value is not empty string. In the case where new value is '0', this is converted to nil and therefore shows as a change, where it shouldn't be.
Fix is to only go into if block if the new value is empty, otherwise do the typecast as normal.
Comments and changes to this ticket
-
DHH December 8th, 2008 @ 11:34 PM
- Assigned user set to Jeremy Kemper
-
Repository December 8th, 2008 @ 11:44 PM
- State changed from new to committed
(from [fc037beedf47ae34bfb3fa5211a29a8299d4607d]) Change field_changed? method to handle the case where a nullable integer column is changed from 0 to '0'
[#1530 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
-
Repository December 8th, 2008 @ 11:44 PM
(from [4130e13436ff501d2615cd5682bab760f5ba7535]) Change field_changed? method to handle the case where a nullable integer column is changed from 0 to '0'
[#1530 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
-
Repository December 8th, 2008 @ 11:44 PM
(from [091e6f791aa3324b2c7f8c8c4cd2fce12b689cc8]) Change field_changed? method to handle the case where a nullable integer column is changed from 0 to '0'
[#1530 state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Tags
Referenced by
- 1530 ActiveRecord::Dirty incorrect behaviour [#1530 state:committed]
- 1530 ActiveRecord::Dirty incorrect behaviour [#1530 state:committed]
- 1530 ActiveRecord::Dirty incorrect behaviour [#1530 state:committed]
- 902 field_changed? does not always typecast before comparison Duplicate of #1530
- 2051 ActiveRecord changes incorrect reports integer column changed when passed a string. This is the same issue as #1530 which was fixed (grab tha...