伙计!我想根据总评分得分对评论进行排序,其中总评分是每个评论的评分评分属性总和。如何基于Ruby on Rails中一组关联中的特定属性的总和对记录进行排序?
class Rating < ActiveRecord::Base
belongs_to :comment, :class_name => 'Comment', :foreign_key => 'comment_id'
end
class Comment < ActiveRecord::Base
has_many :ratings
end
Rating schema
create_table "ratings", force: true do |t|
t.integer "user_id"
t.integer "comment_id"
t.integer "score"
t.datetime "created_at"
t.datetime "updated_at"
end
感谢您的帮助!
你正在使用什么RDBMS? –
MySQL,谢谢。 – nebulus