Larry K. wrote:
I want to have a column in my model that needs to store variable
in a structured manner. For example,:
Equipment type computer:
os: PuppyLinux 2.0.1
Equipment type router:
I would have customized view ( RJS ) that would prompt the user for
correct information based on the EquipmentType selected. The info would
then be stored in one column in the database formatted so that it could
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
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.