title: Rails 4 - query on association count is greater than an attribute
body: <p>I want to do something like "Find all Books where book.pages.count &lt; books.max_pages". </p>
  
  <p>So the models are:</p>
  
  <pre><code>class Book
    has_many :pages
  end
  
  class Page
    belongs_to :book
  end
  </code></pre>
  
  <p>I know I can find books w/ a set number of pages. eg:</p>
  
  <pre><code># Get books w/ &lt; 5 pages.
  Book.joins(:pages).group("books.id").having("count(pages.id) &lt; ?", 5)
  </code></pre>
  
  <p>Is there a good way to do this with a dynamic page count? eg:</p>
  
  <pre><code>Book.joins(:pages).group("books.id").select(.having("count(pages.id) &lt;= book.max_pages")
  </code></pre>
  
  <p>If not I can always just store something inside the Book model (eg <code>book.is_full = false</code> until a save causes it to be full), but this is a bit less flexible if max_pages gets updated.</p>