How to specify a hash in a migration create_table

I want to have a column in my model that needs to store variable
information
in a structured manner. For example,:

Equipment type computer:
ram: 512-mb
os: PuppyLinux 2.0.1

Equipment type router:
manufacturer: LinkSys
ports: 4
wireless: yes

I would have customized view ( RJS ) that would prompt the user for
the
correct information based on the EquipmentType selected. The info would
then be stored in one column in the database formatted so that it could
be
parsed later. I don’t want to create a separate table for each type,

I was thinking that a hash of values would be best. How do I set that
up
in a migration? Should I use a text column type?

On Saturday, July 15, 2006, at 6:37 PM, Larry K. wrote:

ports: 4

http://lists.rubyonrails.org/mailman/listinfo/rails

I’d think long and hard about doing it this way. Perhaps there is a way
to do it using polymorphic associations or by something like a tag that
also holds property information. If you serialize things into a column,
you lose the ability to do any sort of query against it (well, it’s not
easy).

That said, all you have to do in a migration is set up a text column.
Just make sure it can hold the right size object for you.

Then look up ‘serialize’ in the AR API

_Kevin
www.sciwerks.com

Larry K. wrote:

I want to have a column in my model that needs to store variable
information
in a structured manner. For example,:

Equipment type computer:
ram: 512-mb
os: PuppyLinux 2.0.1

Equipment type router:
manufacturer: LinkSys
ports: 4
wireless: yes

I would have customized view ( RJS ) that would prompt the user for
the
correct information based on the EquipmentType selected. The info would
then be stored in one column in the database formatted so that it could
be
parsed later. I don’t want to create a separate table for each type,

I was thinking that a hash of values would be best. How do I set that
up
in a migration? Should I use a text column type?

Well, I don’t agree with Kevin – I think this is a good approach. I use
it in my OpenProfile application, using vCards as the underlying user
data model. I store them in a blob field in the DB table, and just make
sure they’re loaded when the record is loaded, saved when it’s saved,
and parsed/changed appropriately via “facade” methods when they’re
displayed or edited.

It’s a good way to keep chunks of data in varying categories without
undue proliferation of table columns.

You’d have to jump through a few hoops to have and use variable field
names/accessors per record, but I think it could be done without too
much trouble – after all, ActiveRecord already does that.

–Al Evans

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs