PHPackages                             inlm/closure-table - 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. inlm/closure-table

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

inlm/closure-table
==================

Traits for Closure Table in LeanMapper

v1.1.0(8y ago)01.9k1BSD-3-ClausePHPPHP &gt;=5.4.0

Since Mar 6Pushed 7y ago1 watchersCompare

[ Source](https://github.com/inlm/closure-table)[ Packagist](https://packagist.org/packages/inlm/closure-table)[ RSS](/packages/inlm-closure-table/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Closure Table
=============

[](#closure-table)

Traits for Closure Table for LeanMapper.

Installation
------------

[](#installation)

[Download a latest package](https://github.com/inlm/closure-table/releases) or use [Composer](http://getcomposer.org/):

```
composer require inlm/closure-table

```

Library requires PHP 5.4.0 or later.

Example
-------

[](#example)

### Database tables

[](#database-tables)

```
CREATE TABLE `category` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(50) COLLATE utf8mb4_czech_ci NOT NULL,
  `parent_id` int(10) unsigned DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `parent_id` (`parent_id`),
  CONSTRAINT `category_ibfk_2` FOREIGN KEY (`parent_id`) REFERENCES `category` (`id`)
) ENGINE=InnoDB;

CREATE TABLE `category_closure` (
  `ancestor_id` int(10) unsigned NOT NULL,
  `descendant_id` int(10) unsigned NOT NULL,
  `depth` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`ancestor_id`,`descendant_id`),
  KEY `descendant_id` (`descendant_id`),
  CONSTRAINT `category_closure_ibfk_1` FOREIGN KEY (`ancestor_id`) REFERENCES `category` (`id`),
  CONSTRAINT `category_closure_ibfk_2` FOREIGN KEY (`descendant_id`) REFERENCES `category` (`id`)
) ENGINE=InnoDB;
```

### Repository

[](#repository)

```
