PHPackages                             riesenia/persist-related-data - 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. riesenia/persist-related-data

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

riesenia/persist-related-data
=============================

CakePHP ORM plugin for persisting selected fields of related tables

v2.0.0(5mo ago)1141.4k↓28.3%6MITPHPPHP &gt;=8.0CI passing

Since Jun 11Pushed 5mo ago4 watchersCompare

[ Source](https://github.com/riesenia/persist-related-data)[ Packagist](https://packagist.org/packages/riesenia/persist-related-data)[ RSS](/packages/riesenia-persist-related-data/feed)WikiDiscussions master Synced 1mo ago

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

PersistRelatedData behavior for CakePHP
=======================================

[](#persistrelateddata-behavior-for-cakephp)

[![Build Status](https://camo.githubusercontent.com/bc4f78492b192edcec26851c4c10ff2c3d8b394850867a9ace12cf5e8f501fb6/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f72696573656e69612f706572736973742d72656c617465642d646174612f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/riesenia/persist-related-data)[![Latest Version](https://camo.githubusercontent.com/0e5bbdd61ca70e729842ab88e74303be16cfb74c65cff61e0757b6b765f4129b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72696573656e69612f706572736973742d72656c617465642d646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riesenia/persist-related-data)[![Total Downloads](https://camo.githubusercontent.com/b8657b659211f9734c653e7a90dd9baca961a887a8880c36c354efb9bb53f750/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72696573656e69612f706572736973742d72656c617465642d646174612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riesenia/persist-related-data)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

This plugin is for CakePHP 4.x and contains behavior that handles saving selected fields of related data (redundantly).

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

[](#installation)

Update *composer.json* file to include this plugin

```
{
    "require": {
        "riesenia/persist-related-data": "~1.0"
    }
}
```

Load plugin in *config/bootstrap.php*

```
Plugin::load('PersistRelatedData');
```

Usage
-----

[](#usage)

Good example for using this behavior is Invoices model that is related to Contacts. You can provide select box with contacts and save only *contact\_id* when creating new invoice. But when contact data are modified later, your invoice should be left intact.

Example below assumes the *invoices* table has fields *contact\_id*, *contact\_name* and *contact\_address*, while the *contacts* table has fields *name* and *address*. When you save Invoice entity with provided *contact\_id*, fields *contact\_name* and *contact\_address*will be filled automatically.

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

        // add PersistRelatedData behavior
        $this->addBehavior('PersistRelatedData.PersistRelatedData', [
            'fields' => [
                'contact_name' => 'Contacts.name',
                'contact_address' => 'Contacts.address'
            ]
        ]);

        // associations
        $this->belongsTo('Contacts', [
            'foreignKey' => 'contact_id',
            'className' => 'Contacts'
        ]);
    }
}
```

### Changeable fields

[](#changeable-fields)

By default, all fields are automatically overwritten with related data when the foreign key changes. If you want to allow manual edits to persisted fields while still populating them automatically when empty, use the `changeable` configuration option:

```
$this->addBehavior('PersistRelatedData.PersistRelatedData', [
    'fields' => [
        'contact_name' => 'Contacts.name',
        'contact_address' => 'Contacts.address'
    ],
    'changeable' => [
        'contact_name'  // this field can be manually edited
    ]
]);
```

With this configuration:

- **contact\_name** will be populated from related data only if it's empty
- **contact\_address** will always be overwritten with related data when the foreign key changes

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance70

Regular maintenance activity

Popularity37

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 73.5% 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 ~348 days

Recently: every ~820 days

Total

12

Last Release

167d ago

Major Versions

v1.3.0 → v2.0.02025-12-02

PHP version history (2 changes)v1.0.0PHP &gt;=5.4.16

v2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/40c7ed7cfaebeddae57ac4a376c8f21df56dd2f38821b7ba92ea1312ef8020c8?d=identicon)[riesenia](/maintainers/riesenia)

---

Top Contributors

[![segy](https://avatars.githubusercontent.com/u/1355459?v=4)](https://github.com/segy "segy (25 commits)")[![dakota](https://avatars.githubusercontent.com/u/83255?v=4)](https://github.com/dakota "dakota (4 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (2 commits)")[![MasaKni](https://avatars.githubusercontent.com/u/65139438?v=4)](https://github.com/MasaKni "MasaKni (2 commits)")[![Masaker000](https://avatars.githubusercontent.com/u/6486181?v=4)](https://github.com/Masaker000 "Masaker000 (1 commits)")

---

Tags

ormcakephpmaterializerelated

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/riesenia-persist-related-data/health.svg)

```
[![Health](https://phpackages.com/badges/riesenia-persist-related-data/health.svg)](https://phpackages.com/packages/riesenia-persist-related-data)
```

###  Alternatives

[josegonzalez/cakephp-upload

CakePHP plugin to handle file uploading sans ridiculous automagic

5451.3M9](/packages/josegonzalez-cakephp-upload)[muffin/trash

Adds soft delete support to CakePHP ORM tables.

851.3M11](/packages/muffin-trash)[scienta/doctrine-json-functions

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

58723.9M36](/packages/scienta-doctrine-json-functions)[muffin/webservice

Simplistic webservices for CakePHP

88191.0k13](/packages/muffin-webservice)[admad/cakephp-sequence

Sequence plugin for CakePHP to maintain ordered list of records

46489.9k6](/packages/admad-cakephp-sequence)[riesenia/cakephp-duplicatable

CakePHP ORM plugin for duplicating entities (including related entities)

51384.5k4](/packages/riesenia-cakephp-duplicatable)

PHPackages © 2026

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