hyperstack-org / hyperstack-org/hyperstack

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

Aberta
#232 1 comentário 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
JavaScript
Estrelas
538
Forks
41
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

```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).
```

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.