patchEntity overrides/removes data

Hi, I’ve got some problems using patchEntity to update data of an existing entity. I want to create an entity in multiple steps with separate views without saving the entity during the creation process (only at the last step). At the beginning of every step I load the entity from the session and at the end of every step I save the updated entity in the session. I use patchEntity to update the data of the entity with the forms data at the every creation step. Sometimes the data that needs to be updated is nested and I use the associated keyword to define the nested dependencies. The problem is, that the old data gets overwritten when using patchEntity (even if the new data from the request updates completely different fields). Does anyone know what I do wrong?

Here is an example of the entity before patchEntity:

App\Model\Entity\Article Object
(
  [type_id] => 1
  [comments] => Array
  (
    [0] => App\Model\Entity\Comment Object
      (
        [user] => App\Model\Entity\User Object
        (
          [person] => App\Model\Entity\Person Object
          (
            [persondatas] => Array
            (
              [0] => App\Model\Entity\Persondata Object
                (
                  [firstname] => 'Firstname'
                  [lastname] => 'Lastname'
                  ...
                )
            ...
            )
          ...
          )
        ...
        )
      ...
      )
   ...
  )
...
)

Example of request post data:

Array
(
  [comments] => Array
  (
    [0] => Array
      (
        [user] => Array
        (
          [person] => Array
          (
            [persondatas] => Array
            (
              [0] => Array
                (
                  [street] => 'someStreet'
                  [city] => 'someCity'
                )
            )
          )
        )
      )
  )
)

Example of object after patchEntity:

App\Model\Entity\Article Object
(
  [type_id] => 1
  [comments] => Array
  (
    [0] => App\Model\Entity\Comment Object
      (
        [user] => App\Model\Entity\User Object
        (
          [person] => App\Model\Entity\Person Object
          (
            [persondatas] => Array
            (
              [0] => App\Model\Entity\Persondata Object
                (
                  [street] => 'someStreet'
                  [city] => 'someCity'
                  ...
                )
            ...
            )
          ...
          )
        ...
        )
      ...
      )
   ...
  )
...
)

How I use patchEntity:

$article = $session->read('article');
$data = $this->getRequest()->getData();
$article = $this->Articles->patchEntity($article, $data, ['associated' => 'Comments.Users.Persons.Persondatas']);
$session->write('article', $article);

As you can see the firstName and lastName fields were removed by patchEntity.
I would really appreciate some help :slight_smile:

Referring to the docs

It could be because : This happens because CakePHP is reflecting the new state described in the request data.