Sha256: 69bc61955fe104de8aaf4e518f19a01b6be0d49f480584846200f4a22736a2da

Contents?: true

Size: 934 Bytes

Versions: 5

Compression:

Stored size: 934 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}"
        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: id]
          ).update_all(
            [
              "#{parentry_column} = :new_path || subpath(#{parentry_column}, nlevel(:old_path))",
              new_path: new_path, old_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

5 entries across 5 versions & 1 rubygems

Version Path
parentry-1.3.0 lib/parentry/strategy/ltree/instance_methods.rb
parentry-1.2.0 lib/parentry/strategy/ltree/instance_methods.rb
parentry-1.1.0 lib/parentry/strategy/ltree/instance_methods.rb
parentry-1.0.1 lib/parentry/strategy/ltree/instance_methods.rb
parentry-1.0.0 lib/parentry/strategy/ltree/instance_methods.rb