title: Rails - activerecord find using has_many relationship and conditions on the "many" side
body: <p>I'm a complete amateur and I'm sure this is easy...but I'm stuck.</p>
  
  <p>I have a simple situation, I have a table of "activities", each activity can have many "workflows" or statuses leading up to an eventual completion, I need to perform an activerecord find in a controller such that I end up with the activities that do not have any workflows with a status field containing "COMPLETED"</p>
  
  <pre><code>class Activity &lt; ActiveRecord::Base
    has_many :workflows
  
  class Workflow &lt; ActiveRecord::Base
    belongs_to :activity
  </code></pre>
  
  <p>In the controller:</p>
  
  <pre><code>Activity.all(:include =&gt; :workflows, :conditions =&gt; workflows.status != 'COMPLETED')
  </code></pre>
  
  <p>This is working to a degree, but instead of giving me only activites that do not have any workflows with status "COMPLETED", I'm getting results that include activites with a COMPLETED workflow as long as that activity also has other, non-COMPLETED workflows...hope this makes sense.</p>
  
  <p>Bottom line, how can I get back the activities whose workflows, no matter how many there may be, do not include status "COMPLETED:?</p>
  
  <p>Thanks!</p>