Sha256: 1c91d0bcb626a7fcc04e0f3a8e3382b1dcd6ff68654576bf6d69f7f04d37df35

Contents?: true

Size: 921 Bytes

Versions: 2

Compression:

Stored size: 921 Bytes

Contents

module Parentry
  module Strategy
    module Ltree
      module InstanceMethods
        def parse_parentry(input = parentry)
          input.to_s.split('.').map(&:to_i)
        end

        def compute_parentry
          parent.present? ? "#{parent.parentry}.#{id}" : id.to_s
        end

        def cascade_parentry
          old_path, new_path = saved_changes[parentry_column]
          parentry_scope.where(
            ["#{parentry_column} <@ :tree AND id != :id", { tree: old_path, id: }]
          ).update_all(
            [
              "#{parentry_column} = :new_path || subpath(#{parentry_column}, nlevel(:old_path))",
              { new_path:, old_path: }
            ]
          )
        end

        def subtree_conditions
          ["#{parentry_column} <@ ?", parentry]
        end

        def ancestor_conditions
          ["#{parentry_column} @> ?", parentry]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
parentry-1.8.0 lib/parentry/strategy/ltree/instance_methods.rb
parentry-1.7.0 lib/parentry/strategy/ltree/instance_methods.rb