diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-02-04 20:26:11 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-02-08 19:14:29 +0200 |
commit | 2989192d1aa8051aa09164cd097418bd3063d4ad (patch) | |
tree | e277adf2535ac10ed338481ef092731ef84b27e1 /app/models/route.rb | |
parent | bbb7fbcd02c9d9a8a6d6ca44d7ce668b80962c21 (diff) | |
download | gitlab-ce-2989192d1aa8051aa09164cd097418bd3063d4ad.tar.gz |
Store group and project full name and full path in routes tabledz-refactor-full-path
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/models/route.rb')
-rw-r--r-- | app/models/route.rb | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/app/models/route.rb b/app/models/route.rb index dd171fdb069..4eec3e73d5b 100644 --- a/app/models/route.rb +++ b/app/models/route.rb @@ -8,16 +8,22 @@ class Route < ActiveRecord::Base presence: true, uniqueness: { case_sensitive: false } - after_update :rename_descendants, if: :path_changed? + after_update :rename_descendants def rename_descendants - # 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_descendants method - route.update_column(:path, route.path.sub(path_was, path)) + if path_changed? || name_changed? + descendants = Route.where('path LIKE ?', "#{path_was}/%") + + descendants.each do |route| + attributes = { + path: route.path.sub(path_was, path), + name: route.name.sub(name_was, name) + } + + # Note that update_columns skips validation and callbacks. + # We need this to avoid recursive call of rename_descendants method + route.update_columns(attributes) + end end - # rubocop:enable Rails/FindEach end end |