title: How to get all children of a particular type in a polymorphic association
body: <p>I have written a method that works, but feels inelegant. I'm wondering if I've missed a better way.</p>
  
  <p>I have a polymorphic association set up like so;</p>
  
  <pre><code>class Employee &lt; ActiveRecord::Base
    has_many :phones, as: :phoneable
  end
  
  class Client &lt; ActiveRecord::Base
    has_many :phones, as: :phoneable
  end
  
  class Phone &lt; ActiveRecord::Base
    belongs_to :phoneable, polymorphic: true
  end
  </code></pre>
  
  <p>My phones table has standard <code>phoneable_id:integer</code> and <code>phoneable_type:string</code> columns.</p>
  
  <p>What I want to do is get all of the phones for a previously selected group of employees, e.g.</p>
  
  <pre><code>employees = Employee.where role: 'peon'
  </code></pre>
  
  <p>If this was a normal <code>has_many</code> relationship I would then write my phones query as;</p>
  
  <pre><code>Phone.where employee_id: employees
  </code></pre>
  
  <p>To do this in a polymorphic relationship I have written my query as;</p>
  
  <pre><code>Phone.where phoneable_type: 'employee', phoneable_id: employees
  </code></pre>
  
  <p>This works, but I feel like there should be a better way of doing this than explicitly stating the <code>phoneable_type</code>. Does Rails have a way of doing this automagically when presented with a collection of employees, or am I over-reaching for simplicity?</p>