From: Dark Ambient Date: 2006-10-07T04:16:51+09:00 Subject: Re: active record question ------=_Part_140956_32399810.1160162207946 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 10/6/06, Jan Svitok wrote: > > On 10/6/06, Dark Ambient wrote: > > Sorry guys, I try and keep these sorts of questions to the Rails list > but > > I've had little luck over there. Since this is a Ruby / Active Record > > question I thought I'd throw it out here. > > Apologies if it's not appropriate. > > > > Basically I have a form for the user to fill in. Within it are various > > select lists and those are set to multiple, so user can make multiple > > choices. > > I seem to be able to get them into the database using serialize() , but > > integers appear particularly funky with lots of hyphens and quotes. As > well > > these values will be needed for queries and my understanding is that > > serialize is not the way to go. > > > > So I wouldn't mind some recommendations regarding options I might have > to > > accomplish this feat, not including (more tables, if that's possible). > > My initial thoughts and I haven't tried it yet is perhaps using some > type of > > regex to clean them up marshalling out , but not entirely sure if that > makes > > sense. > > I suppose you can clean up the serialized form via custom attribute > setters, getters (AWDwR page 284:) > > class ProductData < ActiveRecord::Base > CU = 18 > def length > read_attribute("length") * CU > end > > def lenght=(inches) > write_attribute("length", Float(inches) / CU) > end > end > > Then it depends on what form is convenient for you and that depends on > the data type and what you plan to do with the data (for example you > could do array.map {|i| i.to_s}.join(',') for an array of integers) > > Disclaimer: not tested, pure theory ;-) > > J. > > I was wondering if there was a tried and true method. I'd imagine this is a fairly common thing with forms and databases. Stuart -- http://en.wikipedia.org/wiki/Dark_ambient ------=_Part_140956_32399810.1160162207946--