Skip to content

Commit

Permalink
Fix reason scoping
Browse files Browse the repository at this point in the history
  • Loading branch information
tumido committed Jan 19, 2018
1 parent 9f04ed5 commit e76a132
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/models/miq_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class MiqRequest < ApplicationRecord
scope :with_approval_state, ->(state) { where(:approval_state => state) }
scope :with_type, ->(type) { where(:type => type) }
scope :with_request_type, ->(type) { where(:request_type => type) }
scope :with_reason, ->(op, reason) { where("reason #{op} ?", reason) }
scope :with_requester, ->(id) { where(:requester_id => User.with_same_userid(id).collect(&:id)) }

MODEL_REQUEST_TYPES = {
Expand Down Expand Up @@ -112,6 +111,13 @@ def self.class_from_request_data(data)
model_symbol.to_s.constantize
end

def self.with_reason_like(reason)
first = reason.first.tr('*', '%')
body = reason[1..-2]
last = reason.last.tr('*', '%')
where("reason LIKE (?)", "#{first}#{sanitize_sql_like(body)}#{last}")
end

# Supports old-style requests where specific request was a seperate table connected as a resource
def resource
self
Expand Down

0 comments on commit e76a132

Please sign in to comment.