夥計!我想根據總評分得分對評論進行排序,其中總評分是每個評論的評分評分屬性總和。如何基於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