summaryrefslogtreecommitdiff
path: root/app/models/route.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/route.rb')
-rw-r--r--app/models/route.rb4
1 files changed, 3 insertions, 1 deletions
diff --git a/app/models/route.rb b/app/models/route.rb
index 91ea2966013..63a0461807b 100644
--- a/app/models/route.rb
+++ b/app/models/route.rb
@@ -2,9 +2,9 @@
class Route < ApplicationRecord
include CaseSensitivity
+ include Gitlab::SQL::Pattern
belongs_to :source, polymorphic: true # rubocop:disable Cop/PolymorphicAssociations
-
validates :source, presence: true
validates :path,
@@ -19,6 +19,8 @@ class Route < ApplicationRecord
after_update :rename_descendants
scope :inside_path, -> (path) { where('routes.path LIKE ?', "#{sanitize_sql_like(path)}/%") }
+ scope :for_routable, -> (routable) { where(source: routable) }
+ scope :sort_by_path_length, -> { order('LENGTH(routes.path)', :path) }
def rename_descendants
return unless saved_change_to_path? || saved_change_to_name?