title: Get newest child on parent.all in one call - Rails 4
body: <p>I have 2 models, <code>orders</code> and <code>order_status_details</code>. The last is just a history of status changes for each order.</p>
  
  <pre><code>class Order &lt; ActiveRecord::Base
      has_many :order_status_details, :dependent =&gt; :destroy
  end
  
  class OrderStatusDetail &lt; ActiveRecord::Base
      belongs_to :order, foreign_key: :order_id
  end
  </code></pre>
  
  <p>Im getting all the orders with this:</p>
  
  <pre><code>@orders = Order.all.order('id DESC')
  </code></pre>
  
  <p>Now, I want to include the newest status. For example:</p>
  
  <pre><code>+----+-----------+---------------------+---------------------+----------+
  | id | status_id | created_at          | updated_at          | order_id |
  +----+-----------+---------------------+---------------------+----------+
  |  1 |         1 | 2016-01-31 04:00:00 | 2016-01-31 04:00:00 |        7 |
  +----+-----------+---------------------+---------------------+----------+
  |  2 |         3 | 2016-01-31 05:00:00 | 2016-01-31 05:00:00 |        7 |
  +----+-----------+---------------------+---------------------+----------+
  |  3 |         5 | 2016-01-31 06:00:00 | 2016-01-31 06:00:00 |        7 |
  +----+-----------+---------------------+---------------------+----------+
  </code></pre>
  
  <p>The correct must be row #3, status #5.</p>
  
  <p>Check my schema.rb:</p>
  
  <pre><code>  create_table "order_status_details", force: :cascade do |t|
      t.integer  "status_id",  limit: 4
      t.datetime "created_at",           null: false
      t.datetime "updated_at",           null: false
      t.integer  "order_id",   limit: 4
    end
  
    create_table "order_statuses", force: :cascade do |t|
      t.string   "name",       limit: 255
      t.datetime "created_at",             null: false
      t.datetime "updated_at",             null: false
      t.boolean  "paid"
    end
  
    create_table "orders", force: :cascade do |t|
      t.integer  "customer_id", limit: 4
      t.decimal  "subtotal",                precision: 10
      t.decimal  "tax",                     precision: 10
      t.decimal  "total",                   precision: 10
      t.integer  "invoice",     limit: 4
      t.integer  "shipping_id", limit: 4
      t.datetime "created_at",                             null: false
      t.datetime "updated_at",                             null: false
      t.decimal  "comission",               precision: 10
      t.string   "comment",     limit: 255
    end
  </code></pre>
  
  <p>How can in one call?</p>
  
  <p>Thanks.</p>