Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 only update serialized attribute when changed

Using Rails 3 I have a number of model containing serialized attributes. To perform the serialization I'm currently using 3 different techniques - the serialize method; activerecord store; and store configurable gem.

In all cases, when I save a model instance the serialized attribute is updated even if the content is unchanged. This was a surprising discovery particularly when using the store configurable gem as the readme states:

"StoreConfigurable is smart enough to let your parent object know when it changes. It is not dumb either. It will only trigger changes if the values you set are different, are new, or change the configs state."

Am I missing a trick here or if this is the expected behaviour is there a way to override it?

like image 373
Chris Hilton Avatar asked Apr 21 '26 20:04

Chris Hilton


2 Answers

Model with serialized columns being saved all the time is the expected behaviour according to this answer.

I haven't tried "store configurable gem" but it sounds like it should be smart enough to detect that.

like image 147
lulalala Avatar answered Apr 25 '26 13:04

lulalala


I have similar issue so before updating i am resetting all the values and let new values to be entered.

like image 42
Amar Avatar answered Apr 25 '26 15:04

Amar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!