I have a database/rails design question. I’d like the user to be able
to specify a set of fields they would like associated with items.
Imagine a shopping cart where each item has a description and price.
But a particular customer may choose to associated a color with all her
items. (it will be site-wide, so every item listed for this particular
user will have this additional field).
I have considered it two ways:
Stored in a pair of tables (keys and fields):
keys: id, user_id, name, type
fields: id, user_id, key_id, item_id, value
(type could be “string” or “number” or something to tell the view how
to render the input box.
Stored in a serialized hash in the item:
item: id, user_id, description, price, add_on_fields
Can someone suggest the merits of each approach? I could make either
work, I think, but I don’t have a good feel for how performance is
affected in each case. They seem similarly complex.