title: How to select document with has_many relation with Mongoid
body: <p>I know that my problem is the trivial one, but I need some help.</p>
  
  <p>I have two mongoid classes with <code>has_many</code> relation:</p>
  
  <pre><code>class Container
      ...
      has_many: items
      ...
  end
  
  class Item
      ...
      field :date, type =&gt; Date
      belongs_to: container
      ...
  end
  </code></pre>
  
  <p>I need all containers that have item at the particular date.</p>
  
  <p>Here is the scope that doesn't work as expected. It returns both, the containters that do have, and the containers that don't have items at the given date:</p>
  
  <pre><code>class Container
      ...
      scope :with_items_on, -&gt;(date){ where(:_id.in =&gt; Item.on(date).only(:container_id).distinct(:container_id)) }
      ...
  end
  </code></pre>
  
  <p><code>.on(date)</code> is scope that returns correctly all Items for the given date.
  Thanks.</p>