# Storing arrays in db

**URL:** <https://www.ruby-forum.com/t/storing-arrays-in-db/196640>\
**Category:** Rails\
**Created:** [April 14, 2008, 11:27pm UTC](https://www.ruby-forum.com/t/storing-arrays-in-db/196640 "2008-04-14T23:27:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [April 14, 2008, 11:27pm UTC](https://www.ruby-forum.com/t/storing-arrays-in-db/196640/1 "2008-04-14T23:27:13Z")

</div>

Hi,

My users can select items and define a quantity attribute for those.  
Those items can be selected with checkboxes. And the quantity is a field  
text.

Collecting all in one form; the checkbox selections, and other details,  
the info should be stored in the db. Resulting in a purchase order for  
example. A single user wouldn’t have many purchase orders in the system  
at one time.

My question is how to store the resulting array in the db? I know how to  
get the array of values but what should I use as the container in the  
db, a single row with a sting hash, store each item separately,  
something else? How can I relate the quantity for each item?

The available items are not predefined, and users can create new items  
into the system also.

I think it is pretty trivial stuff but I would like to get the models  
and logic right from the beginning. Any good suggestions/tutorials?

Thanks.

---

<div class="post-metadata">

**Author:** ![comopasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/59ef9b/32.png) [@comopasta](https://www.ruby-forum.com/u/comopasta)\
**Post date:** [April 14, 2008, 11:58pm UTC](https://www.ruby-forum.com/t/storing-arrays-in-db/196640/2 "2008-04-14T23:58:26Z")

</div>

On Apr 14, 10:27 pm, comopasta Gr [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> My question is how to store the resulting array in the db? I know how to  
> get the array of values but what should I use as the container in the  
> db, a single row with a sting hash, store each item separately,  
> something else? How can I relate the quantity for each item?

Just off the top of my head, i’d think you’d want your purchase order  
class to has\_many :items through :some\_join\_model. The quantity would  
be stored on the join model.

Fred
