# Design question: Storing user fields

**URL:** <https://www.ruby-forum.com/t/design-question-storing-user-fields/99256>\
**Category:** Rails\
**Created:** [January 31, 2006, 6:22am UTC](https://www.ruby-forum.com/t/design-question-storing-user-fields/99256 "2006-01-31T06:22:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [January 31, 2006, 6:22am UTC](https://www.ruby-forum.com/t/design-question-storing-user-fields/99256/1 "2006-01-31T06:22:58Z")

</div>

Hello-

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:

1. 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.

2. 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.

Jake

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [January 31, 2006, 2:24pm UTC](https://www.ruby-forum.com/t/design-question-storing-user-fields/99256/2 "2006-01-31T14:24:20Z")

</div>

Am Dienstag, den 31.01.2006, 06:22 +0100 schrieb Jake J.:

> I have considered it two ways:  
> 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.
> 
> Jake

## I would prefer the second version. It is much more easier to use, but lacks of all benefits you gain from having individual columns for each attribute like validations, sorting or querying. So if you want to do something like this with your attributes you should take the first approach, wich may even result in a better performance then.

Norman T.

[http://blog.inlet-media.de](http://blog.inlet-media.de)

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [January 31, 2006, 5:37pm UTC](https://www.ruby-forum.com/t/design-question-storing-user-fields/99256/3 "2006-01-31T17:37:08Z")

</div>

Norman T. wrote:

> Am Dienstag, den 31.01.2006, 06:22 +0100 schrieb Jake J.:
> 
> > I have considered it two ways:  
> > 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.
> 
> I would prefer the second version. It is much more easier to use, but  
> lacks of all benefits you gain from having individual columns for each  
> attribute like validations, sorting or querying. So if you want to do  
> something like this with your attributes you should take the first  
> approach, wich may even result in a better performance then.

Thanks Norman. I think the database table method seems a bit more  
powerful with regards to search and so on. It will be a fun experiment  
regardless. 🙂

Jake
