Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord::Dirty incorrect behaviour

#1530

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.

Reported by Ben Symonds · December 8th, 2008 @ 02:26 PM

State: committed
Milestone: 2.x
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: none

Activity

  1. DHH
    DHH
    • Assigned user set to Jeremy Kemper

    December 8th, 2008 @ 11:34 PM

  2. Repository
    Repository
    • 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 ActiveRecord::Dirty incorrect behaviour state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...

    December 8th, 2008 @ 11:44 PM

  3. Repository
    Repository

    (from [4130e13436ff501d2615cd5682bab760f5ba7535]) Change field_changed? method to handle the case where a nullable integer column is changed from 0 to '0'

    [#1530 ActiveRecord::Dirty incorrect behaviour state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...

    December 8th, 2008 @ 11:44 PM

  4. Repository
    Repository

    (from [091e6f791aa3324b2c7f8c8c4cd2fce12b689cc8]) Change field_changed? method to handle the case where a nullable integer column is changed from 0 to '0'

    [#1530 ActiveRecord::Dirty incorrect behaviour state:committed]

    Signed-off-by: Jeremy Kemper jeremy@bitsweat.net http://github.com/rails/rails/co...

    December 8th, 2008 @ 11:44 PM