diff --git a/src/Model/Entity/Individual.php b/src/Model/Entity/Individual.php index ef8e5db..471df36 100644 --- a/src/Model/Entity/Individual.php +++ b/src/Model/Entity/Individual.php @@ -7,5 +7,9 @@ use Cake\ORM\Entity; class Individual extends AppModel { - + protected $_accessible = [ + '*' => true, + 'id' => false, + 'uuid' => false, + ]; } diff --git a/src/Model/Table/IndividualsTable.php b/src/Model/Table/IndividualsTable.php index d0df577..79c6982 100644 --- a/src/Model/Table/IndividualsTable.php +++ b/src/Model/Table/IndividualsTable.php @@ -55,26 +55,21 @@ class IndividualsTable extends AppTable return null; } if (empty($existingIndividual)) { - $entity = $this->newEntity($individual, ['associated' => []]); - if (!$this->save($entity)) { - return null; - } - $individual = $entity; + $entity = $this->newEmptyEntity(); + $this->patchEntity($entity, $individual, [ + 'accessibleFields' => ['uuid' => true] + ]); + $entityToSave = $entity; } else { - $reserved = ['id', 'uuid', 'metaFields']; - foreach ($individual as $field => $value) { - if (in_array($field, $reserved)) { - continue; - } - $existingIndividual->$field = $value; - } - if (!$this->save($existingIndividual, ['associated' => false])) { - return null; - } - $individual = $existingIndividua; + $this->patchEntity($existingIndividual, $individual); + $entityToSave = $existingIndividual; } - $this->postCaptureActions($individual); - return $individual->id; + $savedEntity = $this->save($entityToSave, ['associated' => false]); + if (!$savedEntity) { + return null; + } + $this->postCaptureActions($savedEntity); + return $savedEntity->id; } public function postCaptureActions($individual): void