This project is archived and is in readonly mode.

#3474 ✓stale
Matt Jones

_was doesn't work correctly for serialized fields with nested elements

Reported by Matt Jones | November 9th, 2009 @ 06:29 PM

I've been experimenting with dirty tracking for serialized models; the problem I've run into is that will_change! and was don't work with nested arrays/hashes.

Example:

  # o.some_serialized_field starts with { 'a' => [1,2], 'b' => [3,4] }
  o.some_serialized_field_will_change!
  o['a'][0] = 5
  o.some_serialized_field_was # => gives { 'a' => [5,2], 'b' => [3,4] }

The issue is that attribute_will_change! calls clone_attribute, which only calls Object#clone. For now, I'm planning to work around the issue by defining my own some_serialized_field_will_change! method, but it'd be nice for it to work correctly.

Note that this isn't about partial updates (like #2764) or automatic change detection (like #3464 or #360) - this is a glitch in the manual "mark dirty" functionality.

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>

Referenced by

Pages