# Update tables at the same time

**URL:** <https://discourse.cakephp.org/t/update-tables-at-the-same-time/5761>\
**Category:** Need Help\
**Tags:** release\
**Created:** [March 11, 2019, 10:27am UTC](https://discourse.cakephp.org/t/update-tables-at-the-same-time/5761 "2019-03-11T10:27:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zakiy](https://avatars.discourse-cdn.com/v4/letter/z/85e7bf/32.png) [@Zakiy](https://discourse.cakephp.org/u/Zakiy)\
**Post date:** [March 11, 2019, 10:27am UTC](https://discourse.cakephp.org/t/update-tables-at-the-same-time/5761/1 "2019-03-11T10:27:56Z")

</div>

Can anyone please help me for below data. How to update my data among tables at the same time.

Array  
(  
[username] =\> [E53@gmail.com](mailto:E53@gmail.com)  
[email] =\> [E53@gmail.com](mailto:E53@gmail.com)  
[password] =\>  
[role\_id] =\> 3  
[subscriber\_id] =\> 27  
[employee] =\> Array  
(  
[name] =\> E53  
[name\_bengali] =\> E53  
[email] =\> [E53@gmail.com](mailto:E53@gmail.com)  
[designation\_id] =\> 1  
[department\_id] =\> 1  
[contact\_number] =\> 121  
[date\_of\_birth] =\>  
[date\_of\_joining] =\>  
[code] =\> E-000053  
[image] =\> Array  
(  
[tmp\_name] =\> C:\xampp\tmp\phpC308.tmp  
[error] =\> 0  
[name] =\> E-000053.jpg  
[type] =\> image/jpeg  
[size] =\> 6709  
)

```
        [unit_id] => 20
        [is_del] => 
        [is_active] => 1
    )

```

)

---

<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:** [March 12, 2019, 5:42pm UTC](https://discourse.cakephp.org/t/update-tables-at-the-same-time/5761/2 "2019-03-12T17:42:38Z")

</div>

You haven’t shown the association definitions from your models, or the code you’re using to patch your entity. Or specified whether _no_ additional records are being created, or just not everything you want.

---

<div class="post-metadata">

**Author:** ![general2000vn](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@general2000vn](https://discourse.cakephp.org/u/general2000vn)\
**Post date:** [February 21, 2020, 10:22am UTC](https://discourse.cakephp.org/t/update-tables-at-the-same-time/5761/3 "2020-02-21T10:22:25Z")

</div>

basically you need to do these:

- prepare your data in nested array to reflex your models associations properly.
- patchEntity from your top level model, any error occur in any level of model will result top level hasError
- save the top level entity , it will save all of associated model as well, in 1 save() call.
- If the save() get error for any associated model, the saved model on higher level will be rollback, any nothing is saved. (I am not 100% sure of this, but … just try yourself)
