PHPackages                             pchec/cakephp-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. [Database &amp; ORM](/categories/database)
4. /
5. pchec/cakephp-inheritance

AbandonedArchivedCakephp-plugin[Database &amp; ORM](/categories/database)

pchec/cakephp-inheritance
=========================

CakePHP plugin with Single Table Inheritance behavior

1.1(7y ago)026MITPHPPHP &gt;=5.4.16

Since Mar 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/pchec/cakephp-inheritance)[ Packagist](https://packagist.org/packages/pchec/cakephp-inheritance)[ Docs](http://github.com/pchec/cakephp-inheritance)[ RSS](/packages/pchec-cakephp-inheritance/feed)WikiDiscussions dev Synced today

READMEChangelogDependencies (2)Versions (4)Used By (0)

Note: This repository is archived and not maintained.

Inheritance plugin for CakePHP
==============================

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

This plugin enables Single Table Inheritance in CakePHP ORM.

Key Features
------------

[](#key-features)

This plugin allows you to create descendant classes and store their data in one table. One field is used to determine which class the record belongs to. The plugin has two main modes of operation:

- with class hierarchy
- without class hierarchy

Class hierarchy is built as a concatenated string delimitted by `|` character. It is put into the `type` field together with the current type name. This allows ancestors to be aware of their descendants and interact with them using the methods and properties they both share. This is an important feature and can have numerous applications.

If you don't need that feature, you can disable it and use only basic mode, where ancestors and descendants don't directly interact with each other but simply share methods and properties. This is achieved by having the `type` field contain only the current class name.

To illustrate where class hierarchy might be useful, let's look at an example.

Contact is the base class. Client and Supplier are its children. Client has orders, Supplier has deliveries. All Contacts have addresses. A user with permission to see Contact details can potentially view and correct all the addresses, regardless of which descendant class they belong to. However, from the Contact level there is no access to more specific attributes of the children, like orders or deliveries.

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

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require pchec/cakephp-inheritance

```

Usage
-----

[](#usage)

In the base table you intend to use, create the `type` column and make it long, e.g. `varchar(255)`, to give enough room to store more extensivie class hierarchies. By convention, it will be used by the behavior to store the information about the type of the class that the record belongs to. You can use a column with a different name as well, but you will have to define it later in the configuration.

Load the behavior in all the models which are going to use it. Make all the models use the same table name. It is recommend it you name it after the base class.

```
class YourTable extends Table
{
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->table('your_table_name');
        $this->addBehavior('Inheritance.SingleTable');

        // Rest of the initialization code...
    }

    // Rest of the code...
}

```

After you have the base class defined, you can create child classes extending it.

```
class YourChildTable extends YourTable
{
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->table('your_table_name'); // Needs to be the same as in the parent
        $this->addBehavior('Inheritance.SingleTable');

        // Rest of the initialization code...
    }

    // Rest of the code...
}

```

Custom Configuration
--------------------

[](#custom-configuration)

You can turn off class hierarchy generation by setting the `hierarchy` option to `false`.

```
$this->addBehavior('Inheritance.SingleTable', [
	'hierarchy' => false,
]);

```

You can use your own field name instead of `type` by passing it in a `field_name` array key.

```
$this->addBehavior('Inheritance.SingleTable', [
	'field_name' => 'your_field_name',
]);

```

You can also use another table for the behavior column instead of the table used by the class, by setting the `table` option.

```
$this->addBehavior('Inheritance.SingleTable', [
	'table' => 'your_table_name',
]);

```

By default, the class name `YourClassTable` receives the type of `YourClass`. You can customize that by passing the `type` option.

```
$this->addBehavior('Inheritance.SingleTable', [
	'type' => 'your_type_name',
]);

```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~987 days

Total

2

Last Release

2781d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3714330?v=4)[Piotr Chęć](/maintainers/pchec)[@pchec](https://github.com/pchec)

---

Top Contributors

[![pchec](https://avatars.githubusercontent.com/u/3714330?v=4)](https://github.com/pchec "pchec (30 commits)")

---

Tags

cakephpinheritance

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[josegonzalez/cakephp-upload

CakePHP plugin to handle file uploading sans ridiculous automagic

5461.4M11](/packages/josegonzalez-cakephp-upload)[nanigans/single-table-inheritance

Single Table Inheritance Trait

2512.6M3](/packages/nanigans-single-table-inheritance)[muffin/trash

Adds soft delete support to CakePHP ORM tables.

851.4M11](/packages/muffin-trash)[pgbi/cakephp3-soft-delete

SoftDelete plugin for CakePHP

83293.9k](/packages/pgbi-cakephp3-soft-delete)[dereuromark/cakephp-shim

A CakePHP plugin to shim applications between major framework versions.

401.1M21](/packages/dereuromark-cakephp-shim)[muffin/webservice

Simplistic webservices for CakePHP

88194.7k14](/packages/muffin-webservice)

PHPackages © 2026

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