# Association and Filtering

**URL:** <https://www.ruby-forum.com/t/association-and-filtering/189380>\
**Category:** Rails\
**Created:** [May 30, 2010, 7:02pm UTC](https://www.ruby-forum.com/t/association-and-filtering/189380 "2010-05-30T19:02:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![RobZ1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/48db29/32.png) [@RobZ1](https://www.ruby-forum.com/u/RobZ1)\
**Post date:** [May 30, 2010, 7:02pm UTC](https://www.ruby-forum.com/t/association-and-filtering/189380/1 "2010-05-30T19:02:23Z")

</div>

Hopefully a quick one :

I have a products table and in the view I am showing these products as  
well as a sidebar to “filter” the products by team, size, color etc  
(which are all attributes of other join tables). What is the most  
efficient (in terms of best practice) way of getting the filtered list  
in the sidebar? I want to minimise the hits on the database. Is it  
possible to just grab the products and then just show the distinct  
“teams” for example (considering the join association would have  
already grabbed the team name)?

Thanks,  
Rob
