From 579b58c62021633ce8d2822a1a9980e33e6d1445 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 14 Nov 2012 02:48:04 +0100 Subject: [PATCH] Improved result of ticket order. --- app/controllers/tickets_controller.rb | 13 +++++++------ app/models/ticket.rb | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 10621a59f..70ce694f3 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -478,11 +478,12 @@ class TicketsController < ApplicationController end # do query - tickets_all = Ticket.where(conditions). + tickets_all = Ticket.select('DISTINCT(tickets.id)'). + where(conditions). where( '( title LIKE ? OR number LIKE ? OR ticket_articles.body LIKE ? OR ticket_articles.from LIKE ? OR ticket_articles.to LIKE ? OR ticket_articles.subject LIKE ?)', "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%", "%#{query}%" ). - joins(:ticket_articles). + joins(:articles). limit(limit). - order(:created_at) + order('tickets.created_at DESC') # build result list tickets = [] @@ -490,9 +491,9 @@ class TicketsController < ApplicationController tickets_all.each do |ticket| ticket_tmp = Ticket.full_data(ticket.id) tickets.push ticket_tmp - users[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] ) - users[ ticket['customer_id'] ] = User.user_data_full( ticket['customer_id'] ) - users[ ticket['created_by_id'] ] = User.user_data_full( ticket['created_by_id'] ) + users[ ticket['owner_id'] ] = User.user_data_full( ticket_tmp['owner_id'] ) + users[ ticket['customer_id'] ] = User.user_data_full( ticket_tmp['customer_id'] ) + users[ ticket['created_by_id'] ] = User.user_data_full( ticket_tmp['created_by_id'] ) end # return result diff --git a/app/models/ticket.rb b/app/models/ticket.rb index 72856d570..7afa97453 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -4,7 +4,7 @@ class Ticket < ApplicationModel before_destroy :destroy_dependencies belongs_to :group - has_many :ticket_articles, :class_name => 'Ticket::Article', :after_add => :cache_update, :after_remove => :cache_update + has_many :articles, :class_name => 'Ticket::Article', :after_add => :cache_update, :after_remove => :cache_update belongs_to :organization belongs_to :ticket_state, :class_name => 'Ticket::State' belongs_to :ticket_priority, :class_name => 'Ticket::Priority'