Files
danbooru/app/models/note_version.rb
evazion 216d735f24 Fix #3696: API: handle boolean params consistently
* Use ApplicationRecord#attribute_matches to handle boolean attributes
  consistently in search methods.

* Add support for searching various boolean attributes that previously
  weren't supported.
2018-05-03 19:57:14 -05:00

29 lines
757 B
Ruby

class NoteVersion < ApplicationRecord
belongs_to_updater :counter_cache => "note_update_count"
scope :for_user, lambda {|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.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