title: How to find records missing associated records in has_many through association with Active Record?
body: <p>Let'say, we have "Topic - Relationship - Category". </p>
  
  <p>That is, Topic has_many categories through relationship. </p>
  
  <p>I think its very easy to get the topics that with a category</p>
  
  <pre><code>  #Relationship  Model
    Topic_id: integer
    Category_id: integer
  
    @topics=Topic.joins(:relationships)
  </code></pre>
  
  <p>But, not every topic has a category. So how do we retrieve the topic which has no category?
  Is there a <strong>minus</strong> query? </p>
  
  <p>Perhaps it looks like <code>@topics=Topic.where('id NOT IN (?)', Relationship.all)</code>
  I find it in <a href="https://stackoverflow.com/questions/3428852/activerecord-equivalent-to-sql-minus">activerecord equivalent to SQL &#39;minus&#39;</a> but not sure about this solution.</p>