classRoute<ActiveRecord::Basebelongs_to:source,polymorphic: truevalidates:source,presence: truevalidates:path,length: {within: 1..255},presence: true,uniqueness: {case_sensitive: false}after_update:rename_children,if: :path_changed?defrename_children# We update each row separately because MySQL does not have regexp_replace.# rubocop:disable Rails/FindEachRoute.where('path LIKE ?',"#{path_was}%").eachdo|route|# Note that update column skips validation and callbacks.# We need this to avoid recursive call of rename_children methodroute.update_column(:path,route.path.sub(path_was,path))endendend