title: How to do a not exists with a join in rails
body: <p>I'm trying to do a semi complicated query in rails and I'm trying to figure out a way to do it in rails without running raw sql. How it works is I have a list of classes and it joins with table called days and each class has multiple days which is runs on.</p>
  
  <p>I want to have a query where I give a list of days say monday tuesday and thursday and it will give me back a list of classes where all the days it runs on is in the list given.</p>
  
  <p>I have the raw sql I can use but I can't figure out how to get this into a rails command.</p>
  
  <pre><code>select * from webtms_classes c 
  where c.class_id = 'CHEM101'
  and not exists (
    select cd.day from webtms_days cd
    where cd.webtms_class_id = c.id
    and cd.day not in ('Monday','Tuesday','Thursday')
  ) 
  </code></pre>
  
  <p>Heres what the models are:</p>
  
  <pre><code>class WebtmsClass &lt; ActiveRecord::Base
    has_many :webtms_days, dependent: :destroy
  end
  
  class WebtmsDay &lt; ActiveRecord::Base
    belongs_to :webtms_class
  end
  </code></pre>
  
  <p>Any advice?</p>