Larry Kelly
2006-Jul-16 01:37 UTC
[Rails] 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? -- Best Regards, -Larry "Work, work, work...there is no satisfactory alternative." --- E.Taft Benson -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060716/4525d19c/attachment.html
Kevin Olbrich
2006-Jul-16 02:54 UTC
[Rails] how to specify a hash in a migration create_table.
On Saturday, July 15, 2006, at 6:37 PM, Larry Kelly 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? > > >-- >Best Regards, >-Larry >"Work, work, work...there is no satisfactory alternative." > --- E.Taft Benson > > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >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 -- Posted with http://DevLists.com. Sign up and save your mailbox.
Al Evans
2006-Jul-16 12:05 UTC
[Rails] Re: how to specify a hash in a migration create_table.
Larry Kelly 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 -- Posted via http://www.ruby-forum.com/.