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

Inconsistent Behavior of transaction_changed_attributes with store_accessor #36

Open
rohithmsr opened this issue Jan 5, 2025 · 0 comments

Comments

@rohithmsr
Copy link

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!

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

No branches or pull requests

1 participant