【发布时间】:2012-05-14 16:07:08
【问题描述】:
这是我的联想:
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')
【问题讨论】:
-
你能重新表述你的问题吗?
标签: sql ruby-on-rails activerecord