summaryrefslogtreecommitdiffstats
path: root/app/models/principal.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2012-11-13 22:13:39 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2012-11-13 22:13:39 +0000
commit547b85c4ef3105a00de8e9f4c5e7627bd49c7e37 (patch)
treeef8a780466b8033446cdee132514e38662af66ba /app/models/principal.rb
parentd21cfe6bb42966f6ae029c434555482dad2aed30 (diff)
downloadredmine-547b85c4ef3105a00de8e9f4c5e7627bd49c7e37.tar.gz
redmine-547b85c4ef3105a00de8e9f4c5e7627bd49c7e37.zip
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
Diffstat (limited to 'app/models/principal.rb')
-rw-r--r--app/models/principal.rb5
1 files 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)