# 3.10 can't edit associated data from parent FIXED

**URL:** <https://discourse.cakephp.org/t/3-10-cant-edit-associated-data-from-parent-fixed/10024>\
**Category:** Need Help\
**Tags:** help\
**Created:** [December 26, 2021, 5:35pm UTC](https://discourse.cakephp.org/t/3-10-cant-edit-associated-data-from-parent-fixed/10024 "2021-12-26T17:35:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ermias](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ermias/32/1947_2.png) [@Ermias](https://discourse.cakephp.org/u/Ermias)\
**Post date:** [December 26, 2021, 5:35pm UTC](https://discourse.cakephp.org/t/3-10-cant-edit-associated-data-from-parent-fixed/10024/1 "2021-12-26T17:35:04Z")

</div>

```auto
this is my associations at UsersTable
users has one personal info

 $this->addAssociations([
            'hasOne' => [
                
              'Personal_info'=>[
                     'dependent' => true,
                     'cascadeCallbacks' => true,
                     'foreignKey' => 'user_id',
            ],
              'status'=>[
                  
                'dependent' => true,
                'cascadeCallbacks' => true,
            ]
            ]
        ]);

```

```auto
this is my personalInfoTable 
belongsTo Users

$this->belongsTo('Users', [
            'foreignKey' => 'user_id',
            'joinType' => 'INNER',
        ]);

```

my edit action in controller

```auto
public function edit()
    {
        $uuid = $this->Auth->User('uid');

      $edit = $this->Users->get($uuid,['contain'=> 'personal_info']);
        
        if ($this->request->is(['post','put']))
        {
        $this->Users->patchEntity($edit, $this->request->getData(),[
            
            'associated' => [
                'personal_info'
                ]
        ]);

        if ($this->Users->save($edit))
        {
            debug($edit);
            $this->Flash->success('account edited!');
        }else{
            $this->Flash->error('not edited!');
            debug($edit->getErrors());
            debug($edit);
        }
      
       
        
        

        }

    }

```

and then my view temp

```auto
<?php
/**
 * @var \App\View\AppView $this 
 * @var mixed $user
 */

?>

<?php
 echo $this->Form->create();
echo $this->Form->control('username');
echo $this->Form->control('password');
echo $this->Form->control('email');
echo $this->Form->control('phone');
echo $this->Form->hidden('personal_info.pid');
echo $this->Form->control('personal_info.first_name');
echo $this->Form->control('personal_info.middle_name');
echo $this->Form->control('personal_info.last_name');
echo $this->Form->control('personal_info.sex');
echo $this->Form->control('personal_info.age');

echo $this->Form->button('edit');

echo $this->Form->end();

```

my result is it do not update my association entity it creates new entity with the same foriegn key as the editable fiield

```auto
\src\Controller\UsersController.php (line 252)
object(App\Model\Entity\User) {

	'uid' => (int) 45,
	'username' => 'ermiasss',
	'password' => '$2y$10$py.LVQHWZRFZBq1nUzN5.u7c6OThaPKCbETWt//DTz.OVbxZ0gAZO',
	'email' => 'ermiassa@gmail.com',
	'phone' => '0961537212',
	'role' => '3',
	'created' => object(Cake\I18n\FrozenTime) {

		'time' => '2021-12-22 08:32:05.000000+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'modified' => object(Cake\I18n\FrozenTime) {

		'time' => '2021-12-26 17:26:18.027769+00:00',
		'timezone' => 'UTC',
		'fixedNowTime' => false
	
	},
	'Personal_info' => [
		'pid' => (int) 22,
		'first_name' => 'hermela',
		'middle_name' => 'mesfin',
		'last_name' => 'abebe',
		'sex' => (int) 2,
		'age' => (int) 15,
		'user_id' => (int) 45,
		'created' => object(Cake\I18n\FrozenTime) {

			'time' => '2021-12-24 03:27:00.000000+00:00',
			'timezone' => 'UTC',
			'fixedNowTime' => false
		
		},
		'modified' => object(Cake\I18n\FrozenTime) {

			'time' => '2021-12-24 03:27:00.000000+00:00',
			'timezone' => 'UTC',
			'fixedNowTime' => false
		
		}
	],
	'personal_info' => object(App\Model\Entity\PersonalInfo) {

		'first_name' => 'ermias',
		'middle_name' => 'mesfin',
		'last_name' => 'abebe',
		'sex' => (int) 1,
		'age' => (int) 24,
		'user_id' => (int) 45,
		'created' => object(Cake\I18n\FrozenTime) {

			'time' => '2021-12-26 17:26:18.172551+00:00',
			'timezone' => 'UTC',
			'fixedNowTime' => false
		
		},
		'modified' => object(Cake\I18n\FrozenTime) {

			'time' => '2021-12-26 17:26:18.172686+00:00',
			'timezone' => 'UTC',
			'fixedNowTime' => false
		
		},
		'pid' => (int) 31,
		'[new]' => false,
		'[accessible]' => [
			'first_name' => true,
			'middle_name' => true,
			'last_name' => true,
			'sex' => true,
			'age' => true,
			'user_id' => true,
			'created' => true,
			'modified' => true,
			'user' => true
		],
		'[dirty]' => [],
		'[original]' => [],
		'[virtual]' => [],
		'[hasErrors]' => false,
		'[errors]' => [],
		'[invalid]' => [],
		'[repository]' => 'Personal_info'
	
	},
	'[new]' => false,
	'[accessible]' => [
		'username' => true,
		'password' => true,
		'email' => true,
		'phone' => true,
		'role' => true,
		'created' => true,
		'modified' => true,
		'personal_info' => true
	],
	'[dirty]' => [],
	'[original]' => [],
	'[virtual]' => [],
	'[hasErrors]' => false,
	'[errors]' => [],
	'[invalid]' => [],
	'[repository]' => 'Users'

}

```

the users table is good updating but the associate table personal\_info is create new with same foriegn key

 ![Screenshot (70)](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/8/8fec51151248ea8d31dbaa5418d752e31f1034e9.png)  
 ![Screenshot (71)](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/f/f8eb5068a4bfbb30c12c2133c659317b1bf48671.png)

---

<div class="post-metadata">

**Author:** ![brent](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@brent](https://discourse.cakephp.org/u/brent)\
**Post date:** [December 27, 2021, 3:51am UTC](https://discourse.cakephp.org/t/3-10-cant-edit-associated-data-from-parent-fixed/10024/2 "2021-12-27T03:51:31Z")

</div>

At first glance, it appears your associated model name does not follow CakePHP’s naming conventions.

Code wise, my guess is that it is expecting: `$this->hasOne('PersonalInfo')`.

[https://book.cakephp.org/3/en/intro/conventions.html#model-conventions](https://book.cakephp.org/3/en/intro/conventions.html#model-conventions)

[https://book.cakephp.org/3/en/orm/associations.html#hasone-associations](https://book.cakephp.org/3/en/orm/associations.html#hasone-associations)

---

<div class="post-metadata">

**Author:** ![Ermias](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ermias/32/1947_2.png) [@Ermias](https://discourse.cakephp.org/u/Ermias)\
**Post date:** [December 27, 2021, 4:41am UTC](https://discourse.cakephp.org/t/3-10-cant-edit-associated-data-from-parent-fixed/10024/3 "2021-12-27T04:41:08Z")

</div>

i bake the association and also fix annotations

```auto
* @property \Cake\ORM\Table&\Cake\ORM\Association\HasOne $Personal_info
 * @property \App\Model\Table\statusTable&\Cake\ORM\Association\HasOne $status
 */

```

its not the name i think its entity marshalling can you help please

---

<div class="post-metadata">

**Author:** ![Ermias](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ermias/32/1947_2.png) [@Ermias](https://discourse.cakephp.org/u/Ermias)\
**Post date:** [December 27, 2021, 5:50am UTC](https://discourse.cakephp.org/t/3-10-cant-edit-associated-data-from-parent-fixed/10024/4 "2021-12-27T05:50:02Z")

</div>

am trying to edit personal\_info from Users

---

<div class="post-metadata">

**Author:** ![Ermias](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ermias/32/1947_2.png) [@Ermias](https://discourse.cakephp.org/u/Ermias)\
**Post date:** [December 27, 2021, 11:31am UTC](https://discourse.cakephp.org/t/3-10-cant-edit-associated-data-from-parent-fixed/10024/5 "2021-12-27T11:31:48Z")

</div>

i fix it its just remove get() and use find()
