hyperstack-org / hyperstack-org/hyperstack

ActiveRecord::Base#changed? does not pick up on deeper changes to serialized data

未關閉
#232 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
JavaScript
星號
538
分支
41
PR 合併指標
30 天內沒有已合併 PR

描述

```ruby
class MyModel < ApplicationRecord
serialize :data
end

model = MyModel.create(data: {'Amsterdam' => [0, nil])

puts model.changed? # returns false as expected.
model.data['Amsterdam'][1] = 'Capital, not the seat of government'
puts model.changed? # returns false where true is expected.
```
Reason for this seem to be that the `ReactiveRecord::Setters#change_status_and_notify_helper` is not triggered when setting the `model.data['Amsterdam'][1]` value.
The current implementation seems to set a '!CHANGED!' value when changing values in a ActiveRecord attribute. The `ActiveRecord::Base#changed?` function checks for this string and does not compare the ActiveRecord attribute values. A possible solution might be to compare values in case of a serialized ActiveRecord attribute?

Workaround is to change the `model.data` attribute at the base of the structure:
```
puts model.changed? # returns false
model.data['Timmystan'] = [0, 'Place to be']
model.data.delete('Timmystan')
puts model.changed? # returns true where false is expected (as the added data is removed, returning the data structure to its original state).
```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。