Model#search: refactor searching for attributes.

This commit is contained in:
evazion
2019-08-29 20:24:52 -05:00
parent 6fc4b63fa8
commit 7b8584e3b0
26 changed files with 90 additions and 212 deletions

View File

@@ -1,20 +1,13 @@
class NoteVersion < ApplicationRecord
belongs_to :post
belongs_to :note
belongs_to_updater :counter_cache => "note_update_count"
def self.search(params)
q = super
if params[:post_id]
q = q.where(post_id: params[:post_id].split(",").map(&:to_i))
end
if params[:note_id]
q = q.where(note_id: params[:note_id].split(",").map(&:to_i))
end
q = q.attribute_matches(:is_active, params[:is_active])
q = q.attribute_matches(:body, params[:body_matches])
q = q.search_user_attribute(:updater, params)
q = q.search_attributes(params, :updater, :is_active, :post, :note_id)
q = q.text_attribute_matches(:body, params[:body_matches])
q.apply_default_order(params)
end