application record: drop execute_sql, select_value_sql methods.

This commit is contained in:
evazion
2020-02-16 05:27:51 -06:00
parent 9caa9d8117
commit d3bbd82d8b
8 changed files with 19 additions and 69 deletions

View File

@@ -11,16 +11,19 @@ class PostVote < ApplicationRecord
after_create :update_post_on_create
after_destroy :update_post_on_destroy
scope :positive, -> { where("post_votes.score > 0") }
scope :negative, -> { where("post_votes.score < 0") }
def self.positive_user_ids
select_values_sql("select user_id from post_votes where score > 0 group by user_id having count(*) > 100")
positive.group(:user_id).having("count(*) > 100").pluck(:user_id)
end
def self.negative_post_ids(user_id)
select_values_sql("select post_id from post_votes where score < 0 and user_id = ?", user_id)
negative.where(user_id: user_id).pluck(:post_id)
end
def self.positive_post_ids(user_id)
select_values_sql("select post_id from post_votes where score > 0 and user_id = ?", user_id)
positive.where(user_id: user_id).pluck(:post_id)
end
def self.visible(user = CurrentUser.user)