git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10802
e93f8b46-1217-0410-a6f0-
8f06a7374b81
scope :active, :conditions => "#{Principal.table_name}.status = 1"
scope :like, lambda {|q|
+ q = q.to_s
if q.blank?
- {}
+ where({})
else
- q = q.to_s
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)"
params = {:p => pattern}
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))"
params.merge!(:a => a, :b => b)
end
- {:conditions => [sql, params]}
+ where(sql, params)
end
}