From 8051c1c741e14a0df5de30334776fd3b4f785b8c Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 8 Jun 2016 15:25:39 +0200 Subject: [PATCH] Improved related ticket, if we do not have open related tickets, search for any tickets of the customer. --- app/controllers/tickets_controller.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index f291c31b8..efed0db84 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -201,6 +201,18 @@ class TicketsController < ApplicationController .order('created_at DESC') .limit(6) + # if we do not have open related tickets, search for any tickets + if ticket_lists.empty? + ticket_lists = Ticket + .where( + customer_id: ticket.customer_id, + ) + .where(access_condition) + .where('id != ?', [ ticket.id ]) + .order('created_at DESC') + .limit(6) + end + # get related assets ticket_ids_by_customer = [] ticket_lists.each {|ticket_list|