title: How to sort by created_at column of association in rails?
body: <p>Here are my associations:</p>
  
  <pre><code>Class Post
  belongs_to :user
  has_many :favorites, :dependent =&gt; :destroy
  has_many :favoriters, :through =&gt; :favorites, :source =&gt; :user
  end
  
  Class User
  has_many :posts
  has_many :favorites,  :dependent =&gt; :destroy
  has_many :favorited, :through =&gt; :favorites, :source =&gt; :post
  end
  
  Class Favorites
  belongs_to :user, :post
  end
  </code></pre>
  
  <p>I want to sort users' favorite posts by the created_at column of the Favorites association. However, this sorts by the Post created_at attribute, not the Favorites created_at attribute. How can I sort by the Favorites created_at attribute?</p>
  
  <pre><code> @posts=@user.favorited.order('created_at DESC')
  </code></pre>