summaryrefslogtreecommitdiff
path: root/app/models/namespace.rb
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-03-18 23:29:18 +0100
committerRémy Coutable <remy@rymai.me>2016-03-18 23:29:18 +0100
commitcafa408b2521aa82d856581eb5d78d98114f1ab2 (patch)
tree5172e0c5555354d0275c6bf830bdd25e2e116d1c /app/models/namespace.rb
parent0b942541da1dc616cea266dc1f4d517fe81f6e5a (diff)
parent18fc7c66f4455e757593a60e02a6306decef5a47 (diff)
downloadgitlab-ce-cafa408b2521aa82d856581eb5d78d98114f1ab2.tar.gz
Merge remote-tracking branch 'origin/master' into remove-wip
Diffstat (limited to 'app/models/namespace.rb')
-rw-r--r--app/models/namespace.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index bdb33f37495..55842df1e2d 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -52,8 +52,18 @@ class Namespace < ActiveRecord::Base
find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase)
end
+ # Searches for namespaces matching the given query.
+ #
+ # This method uses ILIKE on PostgreSQL and LIKE on MySQL.
+ #
+ # query - The search query as a String
+ #
+ # Returns an ActiveRecord::Relation
def search(query)
- where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
+ t = arel_table
+ pattern = "%#{query}%"
+
+ where(t[:name].matches(pattern).or(t[:path].matches(pattern)))
end
def clean_path(path)