status_trend.rb 818 B

1234567891011121314151617181920212223
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: status_trends
  5. #
  6. # id :bigint(8) not null, primary key
  7. # status_id :bigint(8) not null
  8. # account_id :bigint(8) not null
  9. # score :float default(0.0), not null
  10. # rank :integer default(0), not null
  11. # allowed :boolean default(FALSE), not null
  12. # language :string
  13. #
  14. class StatusTrend < ApplicationRecord
  15. include RankedTrend
  16. belongs_to :status
  17. belongs_to :account
  18. scope :allowed, -> { joins('INNER JOIN (SELECT account_id, MAX(score) AS max_score FROM status_trends GROUP BY account_id) AS grouped_status_trends ON status_trends.account_id = grouped_status_trends.account_id AND status_trends.score = grouped_status_trends.max_score').where(allowed: true) }
  19. end