title: Rails habtm and finding record with no association
body: <p>I have 2 models:</p>
  
  <pre class="lang-rb prettyprint-override"><code>class User &lt; ActiveRecord::Base
      has_and_belongs_to_many :groups
  end
  
  class Group &lt; ActiveRecord::Base
      has_and_belongs_to_many :users
  end
  </code></pre>
  
  <p>I want to make a <strong>scope</strong> (that's important - for efficiency and for ability to chain scopes) that returns Users that doesn't belong to <strong>ANY</strong> Groups.
  After many tries, I failed in doing a method instead of scope, which makes <code>collect</code> on <code>User.all</code> which is ugly and.. not right.</p>
  
  <p>Any help?</p>
  
  <p>And maybe for 2nd question:
  I managed to make a scope that returns Users who belongs to any of given groups (given as an array of id's).</p>
  
  <pre class="lang-rails prettyprint-override"><code>scope :in_groups, lambda { |g|
          {
            :joins      =&gt; :groups,
            :conditions =&gt; {:groups =&gt; {:id =&gt; g}},
            :select     =&gt; "DISTINCT `users`.*" # kill duplicates
          }
        }
  </code></pre>
  
  <p>Can it be better/prettier?
  (Using Rails 3.0.9)</p>