From 547b85c4ef3105a00de8e9f4c5e7627bd49c7e37 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 13 Nov 2012 22:13:39 +0000 Subject: [PATCH] Adds table name to the SQL clause used by Principale.like scope. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10803 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/principal.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/principal.rb b/app/models/principal.rb index 8e7139c35..02b0007f7 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -32,11 +32,12 @@ class Principal < ActiveRecord::Base where({}) else pattern = "%#{q}%" - sql = "LOWER(login) LIKE LOWER(:p) OR LOWER(firstname) LIKE LOWER(:p) OR LOWER(lastname) LIKE LOWER(:p) OR LOWER(mail) LIKE LOWER(:p)" + sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ") params = {:p => pattern} if q =~ /^(.+)\s+(.+)$/ a, b = "#{$1}%", "#{$2}%" - sql << " OR (LOWER(firstname) LIKE LOWER(:a) AND LOWER(lastname) LIKE LOWER(:b)) OR (LOWER(firstname) LIKE LOWER(:b) AND LOWER(lastname) LIKE LOWER(:a))" + sql << " OR (LOWER(#{table_name}.firstname) LIKE LOWER(:a) AND LOWER(#{table_name}.lastname) LIKE LOWER(:b))" + sql << " OR (LOWER(#{table_name}.firstname) LIKE LOWER(:b) AND LOWER(#{table_name}.lastname) LIKE LOWER(:a))" params.merge!(:a => a, :b => b) end where(sql, params) -- 2.39.5