From f5f787758583d31b8e6f4917db3a389211d174af Mon Sep 17 00:00:00 2001 From: Scott Spuler Date: Thu, 22 Aug 2024 06:09:42 -0700 Subject: [PATCH 1/3] saveOptions contains duplicated and originalId --- src/Model/Behavior/DuplicatableBehavior.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Behavior/DuplicatableBehavior.php b/src/Model/Behavior/DuplicatableBehavior.php index 35cb357..4179a03 100644 --- a/src/Model/Behavior/DuplicatableBehavior.php +++ b/src/Model/Behavior/DuplicatableBehavior.php @@ -53,7 +53,7 @@ public function duplicate(int|string $id): EntityInterface|false { return $this->_table->save( $this->duplicateEntity($id), - $this->getConfig('saveOptions') + ['associated' => $this->getConfig('contain')] + $this->getConfig('saveOptions') + ['associated' => $this->getConfig('contain'), 'duplicated' => true, 'originalId' => $id] ); } From 3037d73e597a203b8b6eae93e42a6e3447f326b9 Mon Sep 17 00:00:00 2001 From: Scott Spuler Date: Mon, 3 Mar 2025 11:13:00 -0800 Subject: [PATCH 2/3] Update DuplicatableBehavior.php with duplicatedModel --- src/Model/Behavior/DuplicatableBehavior.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Behavior/DuplicatableBehavior.php b/src/Model/Behavior/DuplicatableBehavior.php index 4179a03..ff05836 100644 --- a/src/Model/Behavior/DuplicatableBehavior.php +++ b/src/Model/Behavior/DuplicatableBehavior.php @@ -53,7 +53,7 @@ public function duplicate(int|string $id): EntityInterface|false { return $this->_table->save( $this->duplicateEntity($id), - $this->getConfig('saveOptions') + ['associated' => $this->getConfig('contain'), 'duplicated' => true, 'originalId' => $id] + $this->getConfig('saveOptions') + ['associated' => $this->getConfig('contain'), 'duplicated' => true, 'originalId' => $id, 'duplicatedModel' => $this->_table->getAlias()] ); } From 8c68efff2e1a8f8a05707ab71e7b3d60f3662c25 Mon Sep 17 00:00:00 2001 From: Scott Spuler Date: Thu, 25 Sep 2025 16:23:46 -0700 Subject: [PATCH 3/3] add saveOptions to duplicate() --- src/Model/Behavior/DuplicatableBehavior.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Model/Behavior/DuplicatableBehavior.php b/src/Model/Behavior/DuplicatableBehavior.php index ff05836..5c2d4c8 100644 --- a/src/Model/Behavior/DuplicatableBehavior.php +++ b/src/Model/Behavior/DuplicatableBehavior.php @@ -47,13 +47,14 @@ class DuplicatableBehavior extends Behavior * Duplicate record. * * @param string|int $id Id of entity to duplicate. + * @param array $saveOptions Additional save options to pass to save(). * @return \Cake\Datasource\EntityInterface|false New entity or false on failure */ - public function duplicate(int|string $id): EntityInterface|false + public function duplicate(int|string $id, array $saveOptions = []): EntityInterface|false { return $this->_table->save( $this->duplicateEntity($id), - $this->getConfig('saveOptions') + ['associated' => $this->getConfig('contain'), 'duplicated' => true, 'originalId' => $id, 'duplicatedModel' => $this->_table->getAlias()] + $this->getConfig('saveOptions') + $saveOptions + ['associated' => $this->getConfig('contain'), 'duplicated' => true, 'originalId' => $id, 'duplicatedModel' => $this->_table->getAlias()] ); }