title: Rails associations NOT EXISTS. Better way?
body: <p>Using Rails 3.2.9<br/>
  I'm attempting to get a list of items that are tied to a organization that do NOT have a owner.</p>
  
  <p>I was able to get a array list using the below but just seems ugly to me. Is there a better way to do this?</p>
  
  <pre><code>Items.all(:select =&gt; "items.id, items.name",
    :joins =&gt; "INNER JOIN organizations on items.organization_id = organizations.id",
    :conditions =&gt; "NOT EXISTS (select * from items k JOIN items_owners on items.id = items_owners.item_id) and items.organization_id = 1")
  </code></pre>
  
  <p>Table Setup:<br/>
  owners:</p>
  
  <ul>
  <li>id</li>
  <li>name</li>
  </ul>
  
  <p>items:</p>
  
  <ul>
  <li>id</li>
  <li>name</li>
  <li>organization_id</li>
  </ul>
  
  <p>items_owners:</p>
  
  <ul>
  <li>owner_id</li>
  <li>item_id</li>
  </ul>
  
  <p>organizations:</p>
  
  <ul>
  <li>id</li>
  <li>List item</li>
  </ul>
  
  <p>Models:</p>
  
  <pre><code>class Organization &lt; ActiveRecord::Base
     attr_accessible :name
  
     has_many :items
  end
  
  class Item &lt; ActiveRecord::Base
     attr_accessible :description, :name, :owner_ids, :organization_id
  
     has_many :items_owner
     has_many :owners, :through =&gt; :items_owner
     belongs_to :organization
  end
  
  class Owner &lt; ActiveRecord::Base
     attr_accessible :name
  
     has_many :items_owner
     has_many :items, :through =&gt; :items_owner
  end
  
  class ItemsOwner &lt; ActiveRecord::Base
     attr_accessible :owner_id, :item_id
  
     belongs_to :item
     belongs_to :owner
  end
  </code></pre>