title: Rails 3: Retrieve all child records where parent model attribute equals search key
body: <p>I want to do a query that returns only the assets that do not have a serial number where the workorder branch equals a number.  </p>
  
  <pre><code>class Workorder &lt; ActiveRecord::Base
      belongs_to :user
      has_many :assets
  
      scope :current_branch, where("branch=350").order("wo_date ASC")
  end
  
  class Asset &lt; ActiveRecord::Base
      belongs_to :workorder
  
      scope :needs_serial, :conditions =&gt;  {:serial =&gt; ""}
  end
  
  class AssetsController &lt; ApplicationController
      def index
          @assets_needing_serial=???
      end
  end
  </code></pre>
  
  <p>So I want a hash of :assets where the assets.workorder.branch="350".  I think I could do a loop and create the hash that way but should I be able to do this in a query?  Should I be trying to use scopes for this?</p>
  
  <p>**Update</p>
  
  <p>This is what I ended up using.  Worked great.</p>
  
  <pre><code>@assets = Asset.joins(:workorder).where('workorders.branch=350').order('workorders.wo_date ASC')
  </code></pre>