Closed
Description
I'm persisting a hash attribute and I would like to make changes to parts of the hash and persist them -- however making changes to just part of a hash doesn't mark the model as changed.
The only way I found to do this so far is to serialize and un-serialize with json -- which decreases performance.
I am looking at the Modis code and it seems it's not responsible for maintaining the changed state.
A simple example of the issue:
class Book
include Modis::Model
attribute :pages, :integer
attribute :desc, :hash
end
b1 = Book.create!(:pages => 100, :desc => { :a => 'good' })
=> #<Book:0x007ffdd7f74bd0
b1.pages = 99
=> 99
b1.changed?
=> true
b1.save
=> true
b1.changed?
=> false
b1.desc = { :a => 'very good' }
=> {:a=>"very good"}
b1.changed?
=> true
b1.save
=> true
b1.changed?
=> false
b1.desc[:a] = 'super good'
=> "super good"
b1.desc
=> {:a=>"super good"}
b1.changed?
=> false
b1.desc = JSON(b1.desc.to_json)
=> {"a"=>"super good"}
b1.changed?
=> true
Metadata
Metadata
Assignees
Labels
No labels