Skip to content
This repository was archived by the owner on Jul 13, 2025. It is now read-only.
This repository was archived by the owner on Jul 13, 2025. It is now read-only.

Inconsistent Behavior of transaction_changed_attributes with store_accessor #36

Description

@rohithmsr

Hi @dylanahsmith @byroot ,

I recently encountered an unexpected behaviour with transaction_changed_attributes.

I’m using ActiveRecord::Store, which provides the store_accessor method. This allows keys in a JSON column to be treated like regular attributes. For instance, in a model (let's call it Subscription), there’s a details JSON field that stores data like start_date and account_id. By defining accessors for these keys, they can be interacted with as normal attributes. More details can be found here

Issue

When updating the start_date nested field directly using:

subscription.update!(details: { "start_date" => "2021-10-23" })  

the change is correctly captured in transaction_changed_attributes.

However, when updating the same field using the store_accessor method:

subscription.update!(start_date: "2019-10-23")  

the change does not get captured in transaction_changed_attributes.

Question

This discrepancy becomes problematic when my logic relies on detecting these changes. Is this behaviour a known limitation, or could I be missing something? I’d greatly appreciate any insights or suggestions you might have!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions