Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When building the :object_changes metadata, use the serialized value for any attributes that are serialized #180

Conversation

TylerRick
Copy link
Contributor

This way, we store the same (serialized) representation of an attribute in object_changes that ActiveRecord itself uses when it stores the attribute value in the model's table.

@TylerRick
Copy link
Contributor Author

Question: This only handles serialization of attributes. Should we also unserialize each serialized attribute using the serializer, the same way read_attribute_before_type_cast does (attribute_methods/serialization.rb)?

      def read_attribute_before_type_cast(attr_name)
        if serialized_attributes.include?(attr_name)
          super.unserialized_value
        else
          super
        end
      end

I'm starting to think that we should, so that version.changeset returns the original, unserialized value the same as record.changes does before saving the record...

…ed attributes.

Now version.changeset returns the same thing that record.changes returned before the save.
@TylerRick
Copy link
Contributor Author

Added a commit which adds unserialization to changeset, similar to what attributes_before_type_cast does (#8078).

Now version.changeset returns the same thing that record.changes returned before the save.

@TylerRick
Copy link
Contributor Author

Note that this issue is not a duplicate of #164. These two pull requests deal with the serialization at different levels and should both be merged in, in my opinion.

#180 takes care of automatically serializing/unserializing any attributes that have a custom serializer defined in the model, while #164 takes care of serializing an updated record's changes hash into the Version#object_changes attribute (which is like adding a custom serializer line to the Version model).

Tyler Rick added 3 commits November 6, 2012 15:09
…_attribute_changes helper

methods, which also do a better job of showing the parallel logic between serializing and
unserializing.
…te values in version.object

(that is, in object_to_string) and when loading attribute values out of version.object (that is, in reify).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants