Dưới đây là các hiệp hội của tôi:Làm thế nào để sắp xếp theo cột created_at của hiệp hội trong đường ray?
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
Tôi muốn sắp xếp bài viết yêu thích của người sử dụng bằng cách cột created_at của hiệp hội yêu thích. Tuy nhiên, điều này sắp xếp theo thuộc tính Post created_at, không phải thuộc tính Favorites created_at. Làm thế nào tôi có thể sắp xếp theo thuộc tính Favorites created_at?
@[email protected]('created_at DESC')
Bạn có thể nói lại câu hỏi của bạn? – beck03076