Model#search: refactor searching for attributes.
This commit is contained in:
@@ -177,25 +177,12 @@ class Upload < ApplicationRecord
|
||||
def search(params)
|
||||
q = super
|
||||
|
||||
q = q.search_user_attribute(:uploader, params)
|
||||
q = q.search_post_id_attribute(params)
|
||||
|
||||
if params[:source].present?
|
||||
q = q.where(source: params[:source])
|
||||
end
|
||||
q = q.search_attributes(params, :uploader, :post, :source, :rating, :parent_id, :server)
|
||||
|
||||
if params[:source_matches].present?
|
||||
q = q.where("uploads.source LIKE ? ESCAPE E'\\\\'", params[:source_matches].to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
if params[:rating].present?
|
||||
q = q.where(rating: params[:rating])
|
||||
end
|
||||
|
||||
if params[:parent_id].present?
|
||||
q = q.attribute_matches(:rating, params[:parent_id])
|
||||
end
|
||||
|
||||
if params[:has_post].to_s.truthy?
|
||||
q = q.where.not(post_id: nil)
|
||||
elsif params[:has_post].to_s.falsy?
|
||||
@@ -214,10 +201,6 @@ class Upload < ApplicationRecord
|
||||
q = q.where("uploads.tag_string LIKE ? ESCAPE E'\\\\'", params[:tag_string].to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
if params[:server].present?
|
||||
q = q.where(server: params[:server])
|
||||
end
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user