# Need a clear view on this

**URL:** <https://www.ruby-forum.com/t/need-a-clear-view-on-this/177229>\
**Category:** Rails\
**Created:** [October 13, 2009, 9:08pm UTC](https://www.ruby-forum.com/t/need-a-clear-view-on-this/177229 "2009-10-13T21:08:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [October 13, 2009, 9:08pm UTC](https://www.ruby-forum.com/t/need-a-clear-view-on-this/177229/1 "2009-10-13T21:08:56Z")

</div>

Hi,

I would like to store possible values in a database, to make them  
available in a select list. The possible values consist of one ore  
more of the values between 1 and 100. So if I would put an example in  
an array, it could be [1,2,19,43,46,81,93]. I’d like to know what the  
best way to store this is. Is it okay to just put this as a comma-  
seperated value into my database? I also thought about binary coding,  
so 1,2,3 would be 111 (=7) and 1,3,4,6 would be 101101 (=45), which I  
think is nice, but could also become very heavy to dissect. However,  
the value would be much easier to validate in my model.

How would you approach this?

Thank you.

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [October 13, 2009, 9:17pm UTC](https://www.ruby-forum.com/t/need-a-clear-view-on-this/177229/2 "2009-10-13T21:17:43Z")

</div>

> How would you approach this?  
> I suppose some of it would depend on the following:

- How many records will have this field?
- How many numbers on average will be in the field?
- How many inserts/selects?

I wouldn’t go with a comma separated string, but I might consider  
using “serialize :my\_field” and then simply stuffing the array into  
the database… all depends on the above I suppose.

I’d also look into why you don’t want to make this a has\_many  
association…

-philip

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [October 13, 2009, 9:51pm UTC](https://www.ruby-forum.com/t/need-a-clear-view-on-this/177229/3 "2009-10-13T21:51:40Z")

</div>

> I suppose some of it would depend on the following:
> 
> - How many records will have this field?

Not too many. For the moment about 90 records.

> - How many numbers on average will be in the field?

At first it will probably only be 1, 2 and 3. It might grow later on  
however.

> - How many inserts/selects?

After the configuration phase almost no inserts or updates, but quite  
some selects. But only one per action, I think.

> I wouldn’t go with a comma separated string, but I might consider  
> using “serialize :my\_field” and then simply stuffing the array into  
> the database… all depends on the above I suppose.

Yes, that might be what I’m looking for. Thank you. Any pro’s and cons  
for this?

> I’d also look into why you don’t want to make this a has\_many  
> association…

I didn’t want to overcomplicate things by creating another HABTM  
association. I do see your point though. I could easily add  
possibilities when needed in the backend without having to change  
anything in the application.

---

<div class="post-metadata">

**Author:** ![jhaagmans](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc8723/32.png) [@jhaagmans](https://www.ruby-forum.com/u/jhaagmans)\
**Post date:** [October 13, 2009, 10:14pm UTC](https://www.ruby-forum.com/t/need-a-clear-view-on-this/177229/4 "2009-10-13T22:14:30Z")

</div>

On Oct 13, 2009, at 12:48 PM, jhaagmans wrote:

> however.
> 
> Yes, that might be what I’m looking for. Thank you. Any pro’s and cons  
> for this?

Based on the above I’d serialize it and not worry about it until it  
becomes a performance issue.

Only real issue is the data is YAML-ized in your database so if you  
want to get it out using something that doesn’t speak YAML you’re  
gonna be frustrated.
