models: refactor class methods into scopes.

This commit is contained in:
evazion
2020-02-17 02:10:08 -06:00
parent 9a8aa1990d
commit 83a0cb0a71
12 changed files with 45 additions and 126 deletions

View File

@@ -21,6 +21,8 @@ class WikiPage < ApplicationRecord
api_attributes including: [:category_name]
scope :active, -> { where(is_deleted: false) }
module SearchMethods
def find_by_id_or_title(id)
if id =~ /\A\d+\z/
@@ -34,10 +36,6 @@ class WikiPage < ApplicationRecord
where(title: normalize_title(title))
end
def active
where("is_deleted = false")
end
def other_names_include(name)
name = normalize_other_name(name)
subquery = WikiPage.from("unnest(other_names) AS other_name").where_iequals("other_name", name)