title: How to fetch parents based on their child's records
body: <p>I have two models like </p>
  
  <p>company.rb</p>
  
  <pre><code>class Company &lt; ApplicationRecord
       has_many :posts
  end
  </code></pre>
  
  <p>post.rb</p>
  
  <pre><code>class Post &lt; ApplicationRecord
      belongs_to :company
  
      scope :notClosed, -&gt; {where(closed: false)}
      scope :published, -&gt; {where(published: true)}
  end
  </code></pre>
  
  <p>I want to fetch companies which carries at least one post with matching post <code>scope</code></p>
  
  <p>Currently my queries is </p>
  
  <pre><code>Company.where(company_type: "Private").all
  </code></pre>
  
  <p>It's return all companies but how to modify this query for my needs.</p>