PHPackages                             riesenia/cakephp-duplicatable - 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/cakephp-duplicatable

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

riesenia/cakephp-duplicatable
=============================

CakePHP ORM plugin for duplicating entities (including related entities)

5.1.0(1y ago)51408.2k↓39.8%18[3 issues](https://github.com/riesenia/cakephp-duplicatable/issues)[2 PRs](https://github.com/riesenia/cakephp-duplicatable/pulls)4MITPHPCI failing

Since Nov 6Pushed 1y ago8 watchersCompare

[ Source](https://github.com/riesenia/cakephp-duplicatable)[ Packagist](https://packagist.org/packages/riesenia/cakephp-duplicatable)[ RSS](/packages/riesenia-cakephp-duplicatable/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (4)Versions (29)Used By (4)

Duplicatable behavior for CakePHP
=================================

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

[![CI](https://github.com/riesenia/cakephp-duplicatable/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/riesenia/cakephp-duplicatable/actions/workflows/ci.yml)[![Coverage Status](https://camo.githubusercontent.com/45d543667d794628def797ad5eff0487053650a9c2a2506e4ca98239226eb498/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f72696573656e69612f63616b657068702d6475706c6963617461626c652e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/riesenia/cakephp-duplicatable)[![Latest Version](https://camo.githubusercontent.com/3b23a3284df3ee6b6e8aaee1dc8600207aff51113d777791d43d0c4923325c1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72696573656e69612f63616b657068702d6475706c6963617461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riesenia/cakephp-duplicatable)[![Total Downloads](https://camo.githubusercontent.com/19189d0ba4c274cdd952ea2f2d09fbf0b93c83e8b3eaba02f1139f799dd120b7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72696573656e69612f63616b657068702d6475706c6963617461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/riesenia/cakephp-duplicatable)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)

This plugin contains a behavior that handles duplicating entities including related data.

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

[](#installation)

Using composer

```
composer require riesenia/cakephp-duplicatable

```

Load plugin using

```
bin/cake plugin load Duplicatable
```

Usage
-----

[](#usage)

This behavior provides multiple methods for your `Table` objects.

### Method `duplicate`

[](#method-duplicate)

This behavior provides a `duplicate` method for the table. It takes the primary key of the record to duplicate as its only argument. Using this method will clone the record defined by the primary key provided as well as all related records as defined in the configuration.

### Method `duplicateEntity`

[](#method-duplicateentity)

This behavior provides a `duplicateEntity` method for the table. It mainly acts as the `duplicate` method except it does not save the duplicated record but returns the Entity to be saved instead. This is useful if you need to manipulate the Entity before saving it.

Configuration options:
----------------------

[](#configuration-options)

- *finder* - finder to use to get entities. Set it to "translations" to fetch and duplicate translations, too. Defaults to "all". It is possible to set an array for more finders.
- *contain* - set related entities that will be duplicated
- *remove* - fields that will be removed from the entity
- *set* - fields that will be set to provide value or callable to modify the value. If you provide a callable, it will take the entity being cloned as the only argument
- *prepend* - fields that will have value prepended by the provided text
- *append* - fields that will have value appended by provided text
- *saveOptions* - options for save on primary table
- *preserveJoinData* - if `_joinData` property in `BelongsToMany` relations should be preserved - defaults to `false` due to tricky nature of this association

Examples
--------

[](#examples)

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

        // add Duplicatable behavior
        $this->addBehavior('Duplicatable.Duplicatable', [
            // table finder
            'finder' => 'all',
            // duplicate also items and their properties
            'contain' => ['InvoiceItems.InvoiceItemProperties'],
            // remove created field from both invoice and items
            'remove' => ['created', 'invoice_items.created'],
            // mark invoice as copied
            'set' => [
                'name' => function($entity) {
                    return md5($entity->name) . ' ' . $entity->name;
                },
                'copied' => true
            ],
            // prepend properties name
            'prepend' => ['invoice_items.invoice_items_properties.name' => 'NEW '],
            // append copy to the name
            'append' => ['name' => ' - copy']
        ]);

        // associations (InvoiceItems table hasMany InvoiceItemProperties)
        $this->hasMany('InvoiceItems', [
            'foreignKey' => 'invoice_id',
            'className' => 'InvoiceItems'
        ]);
    }
}

// ... somewhere in the controller
$this->Invoices->duplicate(4);
```

Sometimes you need to access the original entity, e.g. for setting an ancestor/parent id reference. In this case you can leverage the `$original` entity being passed in as 2nd argument:

```
'set' => [
    'ancestor_id' => function ($entity, $original) {
        return $original->id;
    },
],
```

###  Health Score

49

—

FairBetter than 94% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity50

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 57.7% 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 ~118 days

Recently: every ~371 days

Total

28

Last Release

696d ago

Major Versions

v2.0.0 → v3.0.02016-12-27

3.1.4 → 4.0.0-beta2019-12-18

3.1.5 → 4.0.02020-07-15

3.x-dev → 4.0.12021-05-06

4.0.1 → 5.0.02023-09-29

### Community

Maintainers

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

---

Top Contributors

[![ADmad](https://avatars.githubusercontent.com/u/142658?v=4)](https://github.com/ADmad "ADmad (71 commits)")[![segy](https://avatars.githubusercontent.com/u/1355459?v=4)](https://github.com/segy "segy (34 commits)")[![dereuromark](https://avatars.githubusercontent.com/u/39854?v=4)](https://github.com/dereuromark "dereuromark (6 commits)")[![HavokInspiration](https://avatars.githubusercontent.com/u/5243386?v=4)](https://github.com/HavokInspiration "HavokInspiration (4 commits)")[![EtienneBourque](https://avatars.githubusercontent.com/u/50217898?v=4)](https://github.com/EtienneBourque "EtienneBourque (3 commits)")[![LordSimal](https://avatars.githubusercontent.com/u/9105243?v=4)](https://github.com/LordSimal "LordSimal (2 commits)")[![lorenzo](https://avatars.githubusercontent.com/u/37621?v=4)](https://github.com/lorenzo "lorenzo (2 commits)")[![mfrascati](https://avatars.githubusercontent.com/u/2734747?v=4)](https://github.com/mfrascati "mfrascati (1 commits)")

---

Tags

ormcakephpduplicatecopy

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/riesenia-cakephp-duplicatable/health.svg)

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

###  Alternatives

[josegonzalez/cakephp-upload

CakePHP plugin to handle file uploading sans ridiculous automagic

5461.4M11](/packages/josegonzalez-cakephp-upload)[muffin/trash

Adds soft delete support to CakePHP ORM tables.

881.5M11](/packages/muffin-trash)[muffin/webservice

Simplistic webservices for CakePHP

88196.6k14](/packages/muffin-webservice)[admad/cakephp-sequence

Sequence plugin for CakePHP to maintain ordered list of records

45518.5k7](/packages/admad-cakephp-sequence)[muffin/slug

Slugging support for CakePHP ORM

38278.1k5](/packages/muffin-slug)[josegonzalez/cakephp-version

CakePHP ORM behavior to allow versioning of records

49154.7k](/packages/josegonzalez-cakephp-version)

PHPackages © 2026

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