Store hash in a DB column

I’m just wondering. Is there an easy way to take a hash that I have
and store it in a DB text column and then read it as a hash from it
again.

The reason is that I have a db table called contents. But it stores
all kinds of information and even data that I do not know of yet.

I know I could store it inside the text column using XML or YAML or
something else but then I would have to write some sort of parser to
change the data between the two. So I was hoping that there was some
way of simply storing the hash without conversion in the text field
and get it back as a hash.

then just have a free_form_data column in your db table and AR will
take care of serializing and deserializing your hash or other objects.

What is the datatype of the column?

On Jun 30, 2006, at 9:30 AM, Jon Gretar B. wrote:

way of simply storing the hash without conversion in the text field
and get it back as a hash.

Jon Gretar B.
http://www.jongretar.net/


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

class MyModel < AR::Base

serialize :free_form_data

end

then just have a free_form_data column in your db table and AR will
take care of serializing and deserializing your hash or other objects.

-Ezra

On Jun 30, 2006, at 10:04 AM, Jon wrote:

Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

just use :text

-Ezra

I tried the ways above but not working. Please help.’

Jón Borgþórsson wrote:

On 6/30/06, Ezra Z. [email protected] wrote:

class MyModel < AR::Base

serialize :free_form_data

end

then just have a free_form_data column in your db table and AR will
take care of serializing and deserializing your hash or other objects.

Excellent. I’ll try that.

On 6/30/06, Ezra Z. [email protected] wrote:

class MyModel < AR::Base

serialize :free_form_data

end

then just have a free_form_data column in your db table and AR will
take care of serializing and deserializing your hash or other objects.

Excellent. I’ll try that.