Skip to content

Commit

Permalink
Merge pull request #3218 from DMPRoadmap/template_search_issue_3217
Browse files Browse the repository at this point in the history
Fix for issue #3217 regarding template search feature
  • Loading branch information
briri committed Oct 24, 2022
2 parents 5eff207 + f0f03c0 commit 87abe8c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions app/models/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,16 @@ class Template < ApplicationRecord
}

# Retrieves unarchived templates whose title or org.name includes the term
# passed
# passed(We use search_term_orgs as alias for orgs to avoid issues with
# any orgs table join already present in loaded unarchived.)
scope :search, lambda { |term|
unarchived.joins(:org)
.where('lower(templates.title) LIKE lower(:term) OR ' \
'lower(orgs.name) LIKE lower(:term)',
term: "%#{term}%")
unarchived
.joins(<<~SQL)
JOIN orgs AS search_term_orgs ON search_term_orgs.id = templates.org_id
SQL
.where('lower(templates.title) LIKE lower(:term)' \
'OR lower(search_term_orgs.name) LIKE lower(:term)',
term: "%#{term}%")
}

# defines the export setting for a template object
Expand Down

0 comments on commit 87abe8c

Please sign in to comment.