diff --git a/Gemfile.lock b/Gemfile.lock index 0e7e4cc..3f72c1b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -106,6 +106,3 @@ PLATFORMS DEPENDENCIES pg_ltree! yard - -BUNDLED WITH - 1.10.5 diff --git a/lib/pg_ltree/ltree.rb b/lib/pg_ltree/ltree.rb index fc285f7..f9ead46 100644 --- a/lib/pg_ltree/ltree.rb +++ b/lib/pg_ltree/ltree.rb @@ -191,8 +191,10 @@ def children # # @return [ActiveRecord::Relation] def cascade_update - ltree_scope.where(["#{ltree_path_column} <@ ?", ltree_path_was]).where(["#{ltree_path_column} != ?", ltree_path]). - update_all ["#{ltree_path_column} = ? || subpath(#{ltree_path_column}, nlevel(?))", ltree_path, ltree_path_was] + if ltree_path_was.include? self.id.to_s + ltree_scope.where(["#{ltree_path_column} <@ ?", ltree_path_was]).where(["#{ltree_path_column} != ?", ltree_path]). + update_all ["#{ltree_path_column} = ? || subpath(#{ltree_path_column}, nlevel(?))", ltree_path, ltree_path_was] + end end # Delete all children for current path