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!
Hi @dylanahsmith @byroot ,
I recently encountered an unexpected behaviour with
transaction_changed_attributes.I’m using ActiveRecord::Store, which provides the
store_accessormethod. This allows keys in a JSON column to be treated like regular attributes. For instance, in a model (let's call itSubscription), there’s adetailsJSON field that stores data likestart_dateandaccount_id. By defining accessors for these keys, they can be interacted with as normal attributes. More details can be found hereIssue
When updating the
start_datenested field directly using:the change is correctly captured in
transaction_changed_attributes.However, when updating the same field using the
store_accessormethod: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!