so i have a serialized column :dimensions, and in my migration, i would like to set the field to be a default hash.
i have tried...
create_table :shippin
You can also specify a default class for the serialized column. See the docs.
class MyModel < ActiveRecord::Base
serialize :dimensions_in, Hash
end
I've found that after_initialize blocks can cause a huge performance hit, especially if you would ever need to MyModel.all
(eg: for a bulk export)
Without the class: MyModel.new.dimensions_in => nil
With a default Hash class: MyModel.new.dimensions_in => {}