Move all order logic to models

- Have a default order for each model
-- The overall default is ID DESC
- Allow for custom orderings
-- When comma-separated IDs are used
This commit is contained in:
BrokenEagle
2018-01-28 20:46:18 -08:00
parent f83480cc8a
commit d829ab3a00
49 changed files with 134 additions and 116 deletions

View File

@@ -15,7 +15,6 @@ class ArtistVersion < ApplicationRecord
def search(params)
q = super
return q if params.blank?
if params[:name].present?
q = q.where("name like ? escape E'\\\\'", params[:name].to_escaped_for_sql_like)
@@ -33,13 +32,6 @@ class ArtistVersion < ApplicationRecord
q = q.where(artist_id: params[:artist_id].split(",").map(&:to_i))
end
params[:order] ||= params.delete(:sort)
if params[:order] == "name"
q = q.reorder("name")
else
q = q.reorder("id desc")
end
if params[:is_active] == "true"
q = q.where("is_active = true")
elsif params[:is_active] == "false"
@@ -52,6 +44,13 @@ class ArtistVersion < ApplicationRecord
q = q.where("is_banned = false")
end
params[:order] ||= params.delete(:sort)
if params[:order] == "name"
q = q.order("artist_versions.name").default_order
else
q = q.apply_default_order(params)
end
q
end
end