diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-01-24 17:52:50 +0100 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-01-24 17:52:50 +0100 |
commit | 3cd17c9430c7575b0c1f1041947f3cd0d991f00c (patch) | |
tree | 12638383d600ae6d5c8cbf6c27da7bdb2199f5e7 /app/models/route.rb | |
parent | 8faabdf7d33b575de11b043cfe6698021d33a973 (diff) | |
parent | 8c0e358a972ca9cb2176ff9289a5a89b0c909a93 (diff) | |
download | gitlab-ce-3cd17c9430c7575b0c1f1041947f3cd0d991f00c.tar.gz |
Merge remote-tracking branch 'origin/master' into 24147-delete-env-button
Diffstat (limited to 'app/models/route.rb')
-rw-r--r-- | app/models/route.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/models/route.rb b/app/models/route.rb new file mode 100644 index 00000000000..caf596efa79 --- /dev/null +++ b/app/models/route.rb @@ -0,0 +1,22 @@ +class Route < ActiveRecord::Base + belongs_to :source, polymorphic: true + + validates :source, presence: true + + validates :path, + length: { within: 1..255 }, + presence: true, + uniqueness: { case_sensitive: false } + + after_update :rename_children, if: :path_changed? + + def rename_children + # We update each row separately because MySQL does not have regexp_replace. + # rubocop:disable Rails/FindEach + Route.where('path LIKE ?', "#{path_was}/%").each do |route| + # Note that update column skips validation and callbacks. + # We need this to avoid recursive call of rename_children method + route.update_column(:path, route.path.sub(path_was, path)) + end + end +end |