title: Rails 3, HABTM how to query with conditions
body: <p>I have Awards and Categories, joined with Awards_Categories</p>
  
  <p>I have 2 Categories.</p>
  
  <p>I need to find all the Awards that have Category.id = 1, but not Category.id =2.  Some categories have one or the other, some have just one.  I want a list of the Awards that have category 1 but not category 2.  </p>
  
  <p>I have a  scope: </p>
  
  <pre><code>scope :in_categories, lambda { |categories|
        joins(:categories).
        where(:awards_categories =&gt; { :category_id =&gt; categories } ).
        select("DISTINCT awards.*")
      }
  </code></pre>
  
  <p>And this works with a query like: </p>
  
  <pre><code>@awardsall = Award.in_categories([1 &amp;&amp; 2]).order("name ASC") 
  </code></pre>
  
  <p>I have tried </p>
  
  <pre><code>@awards_store = Award.in_categories([1]).order("name ASC") 
  </code></pre>
  
  <p>With: </p>
  
  <pre><code>&lt;% @awards_store.each do |store| %&gt; 
          &lt;li&gt;&lt;%= link_to store.name, award_path(store), :title =&gt; store.info %&gt; | 
          &lt;% store.categories.each do |cat| %&gt;
              &lt;%= cat.id%&gt;
          &lt;% end %&gt;
      &lt;/li&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>EDIT---
  I know the block is not what I need. it is just my attempt at finding a way to make it work.</p>
  
  <p>And while this lists all the awards, and all the award categories its still grabbing awards that have category.id = 2 because some awards have both</p>
  
  <p>any ideas?</p>