title: Optimizing two level deep association count query
body: <p>I have a visit model as following</p>
  
  <pre><code>class Visit &lt; ActiveRecord::Base
    belongs_to :engineer
    has_many :machines
  end
  </code></pre>
  
  <p>What i'm trying to do is find the number of machines associated with a particular engineer by using following code</p>
  
  <pre><code>count = engineer.visits.map(&amp;:machines).flatten.size
  </code></pre>
  
  <p>is there any better and faster way to do this? I don't want to create a direct association between engineer and machines.</p>