PHPackages                             robotusers/cakephp-table-inheritance - 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. [Framework](/categories/framework)
4. /
5. robotusers/cakephp-table-inheritance

ActiveCakephp-plugin[Framework](/categories/framework)

robotusers/cakephp-table-inheritance
====================================

Robotusers CakePHP STI &amp; CTI pattern plugin

0.5.0(5y ago)4256.6k↓82.5%4MITPHPPHP &gt;=7.2.0CI failing

Since May 20Pushed 2y ago2 watchersCompare

[ Source](https://github.com/robotusers/cakephp-table-inheritance)[ Packagist](https://packagist.org/packages/robotusers/cakephp-table-inheritance)[ Docs](https://github.com/robotusers/cakephp-table-inheritance)[ RSS](/packages/robotusers-cakephp-table-inheritance/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)Dependencies (4)Versions (6)Used By (0)

CakePHP Table Inheritance plugin
================================

[](#cakephp-table-inheritance-plugin)

[![Latest Stable Version](https://camo.githubusercontent.com/47d1aa530d1e3f97aa762f451748efee29e2abf99510a735ffa23ae9ec09b6ca/68747470733a2f2f706f7365722e707567782e6f72672f726f626f7475736572732f63616b657068702d7461626c652d696e6865726974616e63652f762f737461626c65)](https://packagist.org/packages/robotusers/cakephp-table-inheritance)[![Total Downloads](https://camo.githubusercontent.com/cdad5a061050cacdbe611bc893d54282d3fb5d52099af2efa6ff56b065fc7f86/68747470733a2f2f706f7365722e707567782e6f72672f726f626f7475736572732f63616b657068702d7461626c652d696e6865726974616e63652f646f776e6c6f616473)](https://packagist.org/packages/robotusers/cakephp-table-inheritance)[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/c10dfb0ebf3960450df157d936bdbdc5b0477ebbff3b3ae3ae2c969b349e9932/68747470733a2f2f7472617669732d63692e6f72672f726f626f7475736572732f63616b657068702d7461626c652d696e6865726974616e63652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/robotusers/cakephp-table-inheritance)[![codecov](https://camo.githubusercontent.com/43acc3268ed9753996d0957d489539a326e6a95c468ffe36f76341029b0a6c4e/68747470733a2f2f636f6465636f762e696f2f67682f726f626f7475736572732f63616b657068702d7461626c652d696e6865726974616e63652f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/robotusers/cakephp-table-inheritance/branch/master)

This plugin implements [Single Table Inheritance](https://en.wikipedia.org/wiki/Single_Table_Inheritance) (and hopefully will implement Class Table Inheritance in the future) patterns for CakePHP ORM.

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

[](#installation)

CakePHP 4.x

Using composer:

```
composer require robotusers/cakephp-table-inheritance

```

For CakePHP 3.x use version 0.4 of the plugin

```
composer require robotusers/cakephp-table-inheritance:^0.4

```

StiBehavior
-----------

[](#stibehavior)

For now only STI is supported. Just add a behavior to your tables:

```
//in ClientsTable:
public function initialize(array $config)
{
    $this->addBehavior('Robotusers/TableInheritance.Sti', [
        'table' => 'users',
        'discriminator' => 'client'
    ]);
}

//alternative config in AdministratorsTable:
public function initialize(array $config)
{
    $this->table('users');
    $this->addBehavior('Robotusers/TableInheritance.Sti');
    $this->setDiscriminator('admin');
}
```

Now both the `ClientsTable` and `AdministratorsTable` will share `users` db table. A table has to have a `discriminator` field which will be used to determine which model's record is stored in a row.

### Multiple discriminators

[](#multiple-discriminators)

You can also configure a list of allowed discriminators. It's useful for example when working with the files. For example:

```
//in ImagesTable:
public function initialize(array $config)
{
    $this->addBehavior('Robotusers/TableInheritance.Sti', [
        'table' => 'files',
        'discriminatorField' => 'mime',
        'acceptedDiscriminators' => [
            'image/jpeg',
            'image/gif',
            'image/png',
            'image/tiff'
        ]
    ]);
}

//or using wildcards:

public function initialize(array $config)
{
    $this->addBehavior('Robotusers/TableInheritance.Sti', [
        'table' => 'files',
        'discriminatorField' => 'mime',
        'acceptedDiscriminators' => [
            'image/*'
        ]
    ]);
}
```

An `ImagesTable` will share `files` db table and match only specified mime types.

You can also add accepted discriminators on runtime:

```
$table->addAcceptedDiscriminator('image/bmp');
```

### Configuration

[](#configuration)

`StiBehavior` supports following options:

- `discriminatorField` - db table field used to discriminate models, 'discriminator' by default
- `discriminator` - default discriminator value, `$table->alias()` by default
- `table` - db table to share, use this option or `$table->table()` method.
- `checkRules` - `true` by default. Allows to enable/disable build-in rule check for a discriminator value.
- `acceptedDiscriminators` - a list of accepted discriminators.

StiParentBehavior
-----------------

[](#stiparentbehavior)

This plugin also allows to configure parent Table in order to create and hydrate entities based on child tables.

```
//in UsersTable:
public function initialize(array $config)
{
    $this->addBehavior('Robotusers/TableInheritance.StiParent', [
        'tableMap' => [
            'Administrators' => [
                'admin',
                'administrator'
            ],
            'Clients' => 'client'
        ]
    ]);
}
```

`tableMap` option accepts an array mapping table registry aliases to discriminator field values.

You can also map discriminator values to specified table objects using `discriminatorMap` option:

```
//in UsersTable:
public function initialize(array $config)
{
    $this->addBehavior('Robotusers/TableInheritance.StiParent', [
        'discriminatorMap' => [
            'admin' => $this->tableLocator()->get('Administrators'),
            'client' => $this->tableLocator()->get('Clients')
        ]
    ]);
}
```

This behavior also provides `newStiEntity()` method which will proxy `newEntity()` to one of the configured tables based on a discriminator value.

```
$data = [
    'name' => 'super-admin',
    'discriminator' => 'admin'
];

$admin = $this->Users->newStiEntity($data); //will call AdministratorsTable::newEntity() and return an Administrator entity instance.
```

Afterwards you can get a STI table using `stiTable()` method and handle entity using its source `Table` object.

```
$table = $this->Users->stiTable($admin);
$table->save($admin); //it will save an entity using AdministratorsTable
```

You can also directly detect STI table from data array:

```
$data = [
    'name' => 'super-admin',
    'discriminator' => 'admin'
];

$table = $this->Users->stiTable($data);
$admin = $table->newEntity($data);
$table->save($admin);
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 92.2% 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 ~411 days

Total

5

Last Release

2027d ago

PHP version history (4 changes)0.1.0PHP &gt;=5.4

0.3.0PHP &gt;=5.5.9

0.4.0PHP &gt;=5.6

0.5.0PHP &gt;=7.2.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7437773?v=4)[Robert Pustułka](/maintainers/robertpustulka)[@robertpustulka](https://github.com/robertpustulka)

---

Top Contributors

[![robertpustulka](https://avatars.githubusercontent.com/u/7437773?v=4)](https://github.com/robertpustulka "robertpustulka (59 commits)")[![themrwilliams](https://avatars.githubusercontent.com/u/132327?v=4)](https://github.com/themrwilliams "themrwilliams (4 commits)")[![josephshanak](https://avatars.githubusercontent.com/u/5422469?v=4)](https://github.com/josephshanak "josephshanak (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/robotusers-cakephp-table-inheritance/health.svg)

```
[![Health](https://phpackages.com/badges/robotusers-cakephp-table-inheritance/health.svg)](https://phpackages.com/packages/robotusers-cakephp-table-inheritance)
```

###  Alternatives

[cakephp/migrations

Database Migration plugin for CakePHP

14112.5M281](/packages/cakephp-migrations)[jeremyharris/cakephp-lazyload

An association lazy-loader for CakePHP

61610.7k2](/packages/jeremyharris-cakephp-lazyload)[pinguo/php-msf

Pinguo Micro Service Framework For PHP

1.7k4.2k](/packages/pinguo-php-msf)[muffin/tags

Tags plugin for CakePHP

1810.1k](/packages/muffin-tags)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)

PHPackages © 2026

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