Convert models to use new search includes mechanism

This commit is contained in:
BrokenEagle
2020-07-19 03:42:51 +00:00
parent c141a358bd
commit c4009efccd
36 changed files with 208 additions and 125 deletions

View File

@@ -42,9 +42,8 @@ class ArtistUrl < ApplicationRecord
def self.search(params = {})
q = super
q = q.search_attributes(params, :url, :normalized_url, :artist_id, :is_active)
q = q.search_attributes(params, :url, :normalized_url, :is_active)
q = q.artist_matches(params[:artist])
q = q.url_matches(params[:url_matches])
q = q.normalized_url_matches(params[:normalized_url_matches])
@@ -59,11 +58,6 @@ class ArtistUrl < ApplicationRecord
q
end
def self.artist_matches(params = {})
return all if params.blank?
where(artist_id: Artist.search(params).reorder(nil))
end
def self.url_attribute_matches(attr, url)
if url.blank?
all
@@ -134,6 +128,10 @@ class ArtistUrl < ApplicationRecord
errors[:url] << "'#{uri}' is malformed: #{error}"
end
def self.searchable_includes
[:artist]
end
def self.available_includes
[:artist]
end