title: Rails scope on belongs_to association
body: <p>Imagine a Book and a Chapter model. Each Chapter <code>belongs_to :book</code>, and a Book <code>has_many :chapters</code>. We have scopes on the Chapter, for example <code>:very_long</code> returns chapters with over 300 pages.</p>
  
  <p>Many times we want to get all books with any chapters over 300 pages. The way we usually achieve this is like so:</p>
  
  <pre><code># book.rb
  scope :has_very_long_chapter, -&gt; { where(id: Chapter.very_long.select(:book_id) }
  </code></pre>
  
  <p>However, as you can imagine, it gets pretty tedious to proxy the scope every time we want to filter Books by chapter scopes. Is there any more idiomatic or cleaner way to achieve this?</p>