Automatic marshalling with DB access

I have an item which has a hash for one of its fields. When i store it
in the db, i want to do a Marshal.dump of the hash, and similarly, do a
Marshal.load to turn the saved blob back into a hash again.

Is there a way to easily write this into the model, so that it happens
automatically when saving and loading a record?

thanks
max

On Nov 6, 2007 9:01 AM, Max W. [email protected]
wrote:

I have an item which has a hash for one of its fields. When i store it
in the db, i want to do a Marshal.dump of the hash, and similarly, do a
Marshal.load to turn the saved blob back into a hash again.

Is there a way to easily write this into the model, so that it happens
automatically when saving and loading a record?

thanks
max

Check out ActiveRecord::Base.serialize

class Foo < ActiveRecord::Base
serialize :bar
end

HTH,
Michael G.

Michael G. wrote:

Check out ActiveRecord::Base.serialize

ActiveRecord::Base

class Foo < ActiveRecord::Base
serialize :bar
end

HTH,
Michael G.

Yeah, i just discovered that as well, it’s exactly what i was after,
cheers!