# Need suggestion for groups of related options

**URL:** <https://www.ruby-forum.com/t/need-suggestion-for-groups-of-related-options/116025>\
**Category:** Rails\
**Created:** [October 1, 2007, 6:24pm UTC](https://www.ruby-forum.com/t/need-suggestion-for-groups-of-related-options/116025 "2007-10-01T18:24:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![schof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8dc957/32.png) [@schof](https://www.ruby-forum.com/u/schof)\
**Post date:** [October 1, 2007, 6:24pm UTC](https://www.ruby-forum.com/t/need-suggestion-for-groups-of-related-options/116025/1 "2007-10-01T18:24:52Z")

</div>

I’m working on a rails based e-commerce plugin. I have a situation  
where I have a single product and I want to present either multiple  
groups of radio buttons or a series of combo boxes for each of the  
product variations. For example, the product has several different  
options for color and size. I would want to show two combos, one for  
price and one for size.

Product :has\_many variations  
Variation :belongs\_to option, :belongs\_to option\_value

Product#variations will return a mix of color and size option values  
lumped together. I’m looking for a convenient way to get at the  
distinct groups based on option type. The first idea that jumps to  
mind is to use SQL to get the distinct list of types and then do a few  
more queries but that seems query intensive.

Any suggestions on the best way to accomplish this in Rails?

TIA,

Sean

---

<div class="post-metadata">

**Author:** ![schof](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8dc957/32.png) [@schof](https://www.ruby-forum.com/u/schof)\
**Post date:** [October 1, 2007, 9:03pm UTC](https://www.ruby-forum.com/t/need-suggestion-for-groups-of-related-options/116025/2 "2007-10-01T21:03:43Z")

</div>

Your suggestion is what I thought of initially too:

Product  
has\_many :colors, :class\_name =\> ‘Variation’, :conditions =\>  
“option\_id = 1”  
has\_many :sizes, :class\_name =\> ‘Variation’, :conditions =\> “option\_id  
= 2”

mike

schof wrote:

> I’m working on a rails based e-commerce plugin. I have a situation  
> where I have a single product and I want to present either multiple  
> groups of radio buttons or a series of combo boxes for each of the  
> product variations. For example, the product has several different  
> options for color and size. I would want to show two combos, one for  
> price and one for size.
> 
> Product :has\_many variations  
> Variation :belongs\_to option, :belongs\_to option\_value
> 
> Product#variations will return a mix of color and size option values  
> lumped together. I’m looking for a convenient way to get at the  
> distinct groups based on option type. The first idea that jumps to  
> mind is to use SQL to get the distinct list of types and then do a few  
> more queries but that seems query intensive.
> 
> Any suggestions on the best way to accomplish this in Rails?
