views:

114

answers:

1

When rails serializes an object to store in the database it uses YAML. I want to also use Base64 encoding/decoding when doing this so the YAML will be much more compact on INSERT and UPDATE statements. The objects I am serializing are rather large, and Base64 encoding is reducing my insert and update statement times by 70%.

I've been crawling thru the Rails code for the past hour looking for a method I can overwrite, but can't seem to find the correct one. I was thinking that perhaps someone here has already done something similar.

Thanks in advance!

+1  A: 

You're looking for ActiveRecord::Base#serialize. I had a similar problem - I wanted to save a large object into a session, but then decided to create a table and proper class for it instead. Much, much cleaner.

Ahsan Ali
ActiveRecord::Base#serialize only marks the attribute for serilization, it doesn't actually perform the serialization in and out of the database.
robotshapes