This project is archived and is in readonly mode.

#1530 ✓committed
Ben Symonds

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

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