以下是我的联想:
Class Post
belongs_to :user
has_many :favorites, :dependent => :destroy
has_many :favoriters, :through => :favorites, :source => :user
end
Class User
has_many :posts
has_many :favorites, :dependent => :destroy
has_many :favorited, :through => :favorites, :source => :post
end
Class Favorites
belongs_to :user, :post
end
我想按收藏夹关联的 created_at 列对用户最喜欢的帖子进行排序。但是,这是按 Post created_at 属性排序的,而不是 Favorites created_at 属性。如何按收藏夹 created_at 属性排序?
@posts=@user.favorited.order('created_at DESC')