# Problem with patchEntity

**URL:** <https://discourse.cakephp.org/t/problem-with-patchentity/12176>\
**Category:** Need Help\
**Created:** [August 13, 2024, 7:30pm UTC](https://discourse.cakephp.org/t/problem-with-patchentity/12176 "2024-08-13T19:30:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [August 13, 2024, 7:30pm UTC](https://discourse.cakephp.org/t/problem-with-patchentity/12176/1 "2024-08-13T19:30:34Z")

</div>

hey any idea why patchEntity cant work with my data properly?

```auto
            $requestDatanew = [
                'title' => $requestData['title'] ?? null,
                'body' => $requestData['body'] ?? null,
            ];
            
            $article = $this->Articles->patchEntity($article, $requestDatanew, [
                'validate' => 'edit',
                 'accessibleFields' => array_fill_keys(array_keys($requestDatanew), true)
            ]);
            

```

also not with an assassociated table…

```auto
            if (isset($requestData['farms'])) {
    $requestDatanew['farms'] = [];
    
    foreach ($requestData['farms'] as $key => $farm) {
        $requestDatanew['farms'][$key] = [
            'id' => $farm['id'] ?? null,  
            'active' => $farm['active'] ?? null, 
            'title' => $farm['title'] ?? null,

        ];
    }
}

$article = $this->Articles->patchEntity($article, $requestDatanew, [
    'validate' => 'editc',
    'associated' => [
        'Farms' => [
            'accessibleFields' => array_fill_keys(array_keys($requestDatanew['farms'][0] ?? []), true)
        ]
    ]
]);

```

idea? best,

---

<div class="post-metadata">

**Author:** ![Rods](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@Rods](https://discourse.cakephp.org/u/Rods)\
**Post date:** [August 14, 2024, 1:02am UTC](https://discourse.cakephp.org/t/problem-with-patchentity/12176/2 "2024-08-14T01:02:28Z")

</div>

can you provide more details and show some more code?

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [August 14, 2024, 7:44am UTC](https://discourse.cakephp.org/t/problem-with-patchentity/12176/3 "2024-08-14T07:44:15Z")

</div>

i guess its all you need…

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [August 14, 2024, 4:53pm UTC](https://discourse.cakephp.org/t/problem-with-patchentity/12176/4 "2024-08-14T16:53:19Z")

</div>

What does “can’t work” mean?

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [August 14, 2024, 5:23pm UTC](https://discourse.cakephp.org/t/problem-with-patchentity/12176/5 "2024-08-14T17:23:49Z")

</div>

it means no changes on that object after i do the patchentity

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [August 15, 2024, 2:54pm UTC](https://discourse.cakephp.org/t/problem-with-patchentity/12176/6 "2024-08-15T14:54:40Z")

</div>

Are there validation errors? A dump of what `$article` contains after the patch would be useful.

---

<div class="post-metadata">

**Author:** ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)\
**Post date:** [August 15, 2024, 3:46pm UTC](https://discourse.cakephp.org/t/problem-with-patchentity/12176/7 "2024-08-15T15:46:25Z")

</div>

hey, i have no idea why but know its working fine…

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [August 15, 2024, 4:22pm UTC](https://discourse.cakephp.org/t/problem-with-patchentity/12176/8 "2024-08-15T16:22:03Z")

</div>

Might have been a model cache issue.
