title: datagrid scope for Rails 4 about group and order
body: <p>I've been getting confused about the scope in rails 4 all day long.
  I created a model named User with :uid and another model named Letter with :user_uid,:content and something like. And a user has many letters.
  What I want to do is: list each user's latest letter which the letter's content is not null.
  So,in my letters grids I wrote like this：</p>
  
  <pre><code>class Letters
  
    include Datagrid
    scope do
      User.joins(:letters).group(:uid)
             .select(
                "users.*,  MAX(letters.created_at) latest_letter, letters.content, letters.created_at"
              ).order("latest_letter desc").where("letters.content IS NOT NULL")   
    end
  
    filter(:created_at, :date, :range =&gt; true)
  
    column(:id)
    column(:content)
    column(:created_at) do |model|
      format(model.created_at) do
        l model.created_at.to_date, format: :short
      end
    end
  end
  </code></pre>
  
  <p>But I found that the content of letter is not the latest. Anything wrong with my codes?</p>