views:

107

answers:

3

I'm writing a CMS for various forms and such, and I find I'm creating a lot of drop-downs. I don't really feel like mucking up my database with tons of random key/string value tables for simple drop-downs with 2-4 options that change very infrequently. What do you do to manage this in a responsible way?

This is language-agnostic, but I'm working in Rails, if anyone has specific advice.

+3  A: 

You cold have one single dropdown table with an extra column to say what the drop down is for... limit the results with a where clause...

jle
+1  A: 

At my current position, we implemented a LookupCode table that contains a CodeGroup,Code, and Meaning column, as well as some others (like active). That way you have a single table that contains all of your lookup values are in a single location and you can do some quick lookups to bind to your dropdown lists.

Dillie-O
+4  A: 

We put everything into a single LookUp table in the database, with a column that mapped to an enum that described which lookup it was for (title, country, etc.).

This enabled us to add the flexibility of an "Other, please specify" option in lookup dropdowns. We made a control that encapsulated this, with a property to turn this behaviour on or off on a case-by-case basis.

If the end user picked "Other, please specify", a textbox would appear for them to enter their own value. This would be added to the lookup table, but flagged as an ad hoc item.

The table contained a flag denoting the status of each lookup value: Active, Inactive, AdHoc. Only Active ones would appear in the dropdown; AdHoc ones were those created via the "Other, please specify" option.

An admin page showed the frequency of usage of the AdHoc values, allowing the administrators of the site to promote common popular values into general usage (i.e. changing their Status flag to Active).

This may well be overkill for your app, but it worked really well for ours: the app was basically almost entirely CRUD operations on very business-specific data. We had dozens of lookups throughout the site that the customer wanted to be able to maintain themselves. This gave them total flexibility with no intervention from us.

teedyay
I really like this idea. Not sure if I'll go with something quite as elaborate, but definitely good food for thought.
Jon Smock
How did you make sure your various drop-downs were pointed at the right group? Did you hardcode the group key into your code?
Jon Smock
We'd set the property each time we put an instance of the lookup control on a page. This is dead easy to do declaratively in asp.net; I've not worked in Ruby. The control would die horribly if we forgot to set it, so we'd see this immediately when debugging.
teedyay