Improved result of ticket order.

This commit is contained in:
Martin Edenhofer 2012-11-14 02:48:04 +01:00
parent df141b153a
commit 579b58c620
2 changed files with 8 additions and 7 deletions

View file

@ -478,11 +478,12 @@ class TicketsController < ApplicationController
end end
# do query # 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}%" ). 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). limit(limit).
order(:created_at) order('tickets.created_at DESC')
# build result list # build result list
tickets = [] tickets = []
@ -490,9 +491,9 @@ class TicketsController < ApplicationController
tickets_all.each do |ticket| tickets_all.each do |ticket|
ticket_tmp = Ticket.full_data(ticket.id) ticket_tmp = Ticket.full_data(ticket.id)
tickets.push ticket_tmp tickets.push ticket_tmp
users[ ticket['owner_id'] ] = User.user_data_full( ticket['owner_id'] ) users[ ticket['owner_id'] ] = User.user_data_full( ticket_tmp['owner_id'] )
users[ ticket['customer_id'] ] = User.user_data_full( ticket['customer_id'] ) users[ ticket['customer_id'] ] = User.user_data_full( ticket_tmp['customer_id'] )
users[ ticket['created_by_id'] ] = User.user_data_full( ticket['created_by_id'] ) users[ ticket['created_by_id'] ] = User.user_data_full( ticket_tmp['created_by_id'] )
end end
# return result # return result

View file

@ -4,7 +4,7 @@ class Ticket < ApplicationModel
before_destroy :destroy_dependencies before_destroy :destroy_dependencies
belongs_to :group 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 :organization
belongs_to :ticket_state, :class_name => 'Ticket::State' belongs_to :ticket_state, :class_name => 'Ticket::State'
belongs_to :ticket_priority, :class_name => 'Ticket::Priority' belongs_to :ticket_priority, :class_name => 'Ticket::Priority'