PHPackages                             previousnext/nested-set - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. previousnext/nested-set

ActiveLibrary[Database &amp; ORM](/categories/database)

previousnext/nested-set
=======================

A PHP Doctrine DBAL implementation for Nested Sets.

2.0.1(3y ago)151.1M—1.3%8[5 PRs](https://github.com/previousnext/nested-set/pulls)GPL-2.0-or-laterPHPPHP &gt;=8.0

Since Feb 15Pushed 3y ago10 watchersCompare

[ Source](https://github.com/previousnext/nested-set)[ Packagist](https://packagist.org/packages/previousnext/nested-set)[ RSS](/packages/previousnext-nested-set/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (10)Versions (14)Used By (0)

Nested Set
==========

[](#nested-set)

A PHP Doctrine DBAL implementation for Nested Sets.

[![CircleCI](https://camo.githubusercontent.com/43343e02110b6cc80edba2d2902b340bef970aa29fc789d056bd861167fc226e/68747470733a2f2f636972636c6563692e636f6d2f67682f70726576696f75736e6578742f6e65737465642d7365742e7376673f7374796c653d737667)](https://circleci.com/gh/previousnext/nested-set)

Using
-----

[](#using)

### Create table schema

[](#create-table-schema)

Create the table schema, passing in a a [DBAL connection](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#getting-a-connection) and table name (defaults to 'tree').

```
$schema = new DbalNestedSetSchema($connection, 'my_tree');
schema->create();
```

### Set up the nested set client

[](#set-up-the-nested-set-client)

Create a new `DbalNestedSet` passing in the DBAL connection and the table name.

```
$nestedSet = new DbalNestedSet($connection, 'my_tree');
```

### Add a root node

[](#add-a-root-node)

A NodeKey represents a unique ID for a node in the tree. It supports the idea of a node ID and a revision ID, mostly for compatibility with Drupal.

```
$nodeKey = new NodeKey($id, $revisionId);
$rootNode = $nestedSet->addRootNode($nodeKey);
```

### Add a child node

[](#add-a-child-node)

To add a child node, you provide the parent node, and a child node key.

```
$nodeKey = new NodeKey($id, $revisionId);
$nestedSet->addNodeBelow($rootNode, $nodeKey);
```

### Find Descendants

[](#find-descendants)

To find descendents, you provide the parent node key.

```
$nodeKey = new NodeKey($id, $revisionId);
$descendants = $this->nestedSet->findDescendants($nodeKey);
```

### Find ancestors

[](#find-ancestors)

To find ancestors, you provide the child node key.

```
$nodeKey = new NodeKey($id, $revisionId);
$ancestors = $this->nestedSet->findAncestors($nodeKey);
```

See `\PNX\NestedSet\NestedSetInterface` for many more methods that can be used for interacting with the nested set.

Developing
----------

[](#developing)

### Dependencies

[](#dependencies)

To install all dependencies, run:

```
make init

```

### Linting

[](#linting)

Uses the Drupal coding standard.

To validate code sniffs run:

```
make lint-php

```

To automatically fix code sniff issues, run:

```
make fix-php

```

### Testing

[](#testing)

To run all phpunit tests, run:

```
make test

```

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 62.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~211 days

Recently: every ~161 days

Total

11

Last Release

1265d ago

Major Versions

0.2.0 → 1.0.02021-02-22

1.x-dev → 2.0.02022-07-12

PHP version history (2 changes)0.2.0PHP ^7.3 || ^8.0

2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6132?v=4)[Kim Pepper](/maintainers/kimpepper)[@kimpepper](https://github.com/kimpepper)

---

Top Contributors

[![kimpepper](https://avatars.githubusercontent.com/u/6132?v=4)](https://github.com/kimpepper "kimpepper (39 commits)")[![larowlan](https://avatars.githubusercontent.com/u/555254?v=4)](https://github.com/larowlan "larowlan (19 commits)")[![simesy](https://avatars.githubusercontent.com/u/188856?v=4)](https://github.com/simesy "simesy (2 commits)")[![acbramley](https://avatars.githubusercontent.com/u/569927?v=4)](https://github.com/acbramley "acbramley (1 commits)")[![pnx-test](https://avatars.githubusercontent.com/u/18455685?v=4)](https://github.com/pnx-test "pnx-test (1 commits)")

---

Tags

php-lib

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/previousnext-nested-set/health.svg)

```
[![Health](https://phpackages.com/badges/previousnext-nested-set/health.svg)](https://phpackages.com/packages/previousnext-nested-set)
```

###  Alternatives

[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58723.9M36](/packages/scienta-doctrine-json-functions)[martin-georgiev/postgresql-for-doctrine

Extends Doctrine with native PostgreSQL support for arrays, JSONB, ranges, PostGIS geometries, text search, ltree, uuid, and 100+ PostgreSQL-specific functions.

4485.3M4](/packages/martin-georgiev-postgresql-for-doctrine)[damienharper/auditor-bundle

Integrate auditor library in your Symfony projects.

4542.8M](/packages/damienharper-auditor-bundle)[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[worksome/foggy

Foggy is a tool for making database dumps with some data removed/changed.

26571.7k1](/packages/worksome-foggy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
