Files
danbooru/app/models/note_version.rb
evazion 0eff095a3e Refactor searching text attributes.
* Allow using ApplicationRecord#attribute_matches to search text attributes,
and standardize models on using this instead of duplicating code.

* Remove restrictions that limited wildcard searches to Builders only in various places.
2018-08-31 19:50:46 -05:00

30 lines
810 B
Ruby

class NoteVersion < ApplicationRecord
belongs_to_updater :counter_cache => "note_update_count"
scope :for_user, ->(user_id) {where("updater_id = ?", user_id)}
def self.search(params)
q = super
if params[:updater_id]
q = q.where(updater_id: params[:updater_id].split(",").map(&:to_i))
end
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.apply_default_order(params)
end
def previous
NoteVersion.where("note_id = ? and updated_at < ?", note_id, updated_at).order("updated_at desc").first
end
end