##// END OF EJS Templates
Adds table name to the SQL clause used by Principale.like scope....
Jean-Philippe Lang -
r10579:547b85c4ef31
parent child
Show More
@@ -32,11 +32,12 class Principal < ActiveRecord::Base
32 where({})
32 where({})
33 else
33 else
34 pattern = "%#{q}%"
34 pattern = "%#{q}%"
35 sql = "LOWER(login) LIKE LOWER(:p) OR LOWER(firstname) LIKE LOWER(:p) OR LOWER(lastname) LIKE LOWER(:p) OR LOWER(mail) LIKE LOWER(:p)"
35 sql = %w(login firstname lastname mail).map {|column| "LOWER(#{table_name}.#{column}) LIKE LOWER(:p)"}.join(" OR ")
36 params = {:p => pattern}
36 params = {:p => pattern}
37 if q =~ /^(.+)\s+(.+)$/
37 if q =~ /^(.+)\s+(.+)$/
38 a, b = "#{$1}%", "#{$2}%"
38 a, b = "#{$1}%", "#{$2}%"
39 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))"
39 sql << " OR (LOWER(#{table_name}.firstname) LIKE LOWER(:a) AND LOWER(#{table_name}.lastname) LIKE LOWER(:b))"
40 sql << " OR (LOWER(#{table_name}.firstname) LIKE LOWER(:b) AND LOWER(#{table_name}.lastname) LIKE LOWER(:a))"
40 params.merge!(:a => a, :b => b)
41 params.merge!(:a => a, :b => b)
41 end
42 end
42 where(sql, params)
43 where(sql, params)
General Comments 0
You need to be logged in to leave comments. Login now