models: replace raw LIKE queries with where_like.

This commit is contained in:
evazion
2020-01-22 13:21:31 -06:00
parent 9d71c77524
commit 22cb0ea322
10 changed files with 28 additions and 29 deletions

View File

@@ -43,14 +43,14 @@ class WikiPage < ApplicationRecord
end
def other_names_include(name)
name = normalize_other_name(name).downcase
subquery = WikiPage.from("unnest(other_names) AS other_name").where("lower(other_name) = ?", name)
name = normalize_other_name(name)
subquery = WikiPage.from("unnest(other_names) AS other_name").where_iequals("other_name", name)
where(id: subquery)
end
def other_names_match(name)
if name =~ /\*/
subquery = WikiPage.from("unnest(other_names) AS other_name").where("other_name ILIKE ?", name.to_escaped_for_sql_like)
subquery = WikiPage.from("unnest(other_names) AS other_name").where_ilike("other_name", name)
where(id: subquery)
else
other_names_include(name)