diff --git a/app/models/miq_request.rb b/app/models/miq_request.rb index 30e24b09928..597648f5587 100644 --- a/app/models/miq_request.rb +++ b/app/models/miq_request.rb @@ -114,7 +114,7 @@ def self.class_from_request_data(data) def self.with_reason_like(reason) # Reason string uses * wildcard, scope is required to convert it into % wildcard for LIKE statement reason = reason.match(/\A(?\*?)(?.*?)(?\*?)\z/) - where("reason LIKE (?)", "#{reason[:start] ? '%' : ''}#{sanitize_sql_like(reason[:content])}#{reason[:end] ? '%' : ''}") + joins(:miq_approvals).where("miq_approvals.reason LIKE (?)", "#{reason[:start] ? '%' : ''}#{sanitize_sql_like(reason[:content])}#{reason[:end] ? '%' : ''}") end # Supports old-style requests where specific request was a seperate table connected as a resource