On 20 October 2011 11:46, Peter Hicks <[email protected]> wrote: > All, > > I have some data that could be a combination of around 30 values. Typical > values could be 'TB', 'TF', 'D', 'U', '-D', 'OP', 'RM', or nil. > > Ideally, I'd use the SET data type in PostgreSQL, but ActiveRecord doesn't > appear to support[1] this. More specifically, I can run a migration on my > development database, but db/schema.rb contains a comment about an > unsupported data-type. > > I've considered creating 30 columns to model this, however I'm not convinced > that's efficient. I've also thought about separating each value with a : > and storing this - for example, ":TF:-D:" - whilst I can query for "WHERE > foo LIKE '%:D:%'", that probably isn't indexable as it's a text search. > > Can anyone help me to come up with an efficient way to do this in Rails > 3.0.10?
If the attributes are effectively independent, so that a record may be a TB or it may not, and it may be a TF or it may not, and so on, then use 30 (or whatever) boolean columns as that is the simplest way to do it and it most closely maps to your requirement. I don't see in what way this would be inefficient. It would surely be the most efficient solution when it comes to finding records of particular types. In any case you should not worry about efficiency at this stage. Start with the most straight forward design and *if* performance becomes an issue then optimise it later. I can virtually guarantee that the bottleneck in a app will not be where you expect to be at the outset, so starting with a more complex (and potentially buggy) solution in order to work around perceived bottlenecks is rarely a good idea. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

