# Success save but one or more field didn't saved

**URL:** <https://discourse.cakephp.org/t/success-save-but-one-or-more-field-didnt-saved/8303>\
**Category:** Need Help\
**Created:** [August 28, 2020, 5:09pm UTC](https://discourse.cakephp.org/t/success-save-but-one-or-more-field-didnt-saved/8303 "2020-08-28T17:09:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arizzoye](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@arizzoye](https://discourse.cakephp.org/u/arizzoye)\
**Post date:** [August 28, 2020, 5:09pm UTC](https://discourse.cakephp.org/t/success-save-but-one-or-more-field-didnt-saved/8303/1 "2020-08-28T17:09:01Z")

</div>

good night, and enjoy with coffee.  
I have trouble while saving Users table.

The messages was successfull to save, but display in index, there’s one or more fields didn’t saved.

I have used relation

```auto
Country hasMany Users
Province hasMany Users

```

below this sample `UsersController`

```auto
public function add()
    {
        $user = $this->Users->newEntity();
		$user->Dibuat = (Time::now())->i18nFormat('dd-MM-yyyy HH:mm:ss');
        if ($this->request->is('post')) {
            $user = $this->Users->patchEntity($user, $this->request->getData());
            if ($this->Users->save($user)) {
                $this->Flash->success(__('Pengguna berhasil ditambahkan.'));

                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('Pengguna gagal ditambahkan, atau ada input yang sama, atau ada input yang salah, atau ada input yang kosong, atau administrator lebih dari 2 coba lagi.'));
        }
        $countries = $this->Users->Countries->find('list', ['limit' => 200]);
        $provinces = $this->Users->Provinces->find('list', ['limit' => 200]);
   }

```

and this model table countries, Provinces and users

```auto
UsersTable.php
$this->belongsTo('Countries', [
       'foreignKey' => 'countrie_id',
     ]);
 $this->belongsTo('Provinces', [
       'foreignKey' => 'province_id',
     ]);

CountriesTable.php
$this->hasMany('Users', [
      'foreignKey' => 'countrie_id'
	]);

ProvincesTable.php
$this->hasMany('Users', [
      'foreignKey' => 'province_id',
    ]);

```

and this below isnide entity

```auto
User.php
protected $_accessible = [
        'Nama' => true,
        'Whatsapp' => true,
        'Email' => true,
        'Password' => true,
        'Role' => true,
        'Approvesuplier' => true,
        'photo' => true,
        'photo_dir' => true,
        'photo_size' => true,
        'photo_type' => true,
        'countrie_id' => true,
        'province_id' => true,
 ];

Country.php
protected $_accessible = [
        'Negara' => true,
	'provinces' => true,
	'users' => true,
 ];

Province.php
protected $_accessible = [
        'countrie_id' => true,
        'Provinsi' => true,
        'country' => true,
        'users' => true,
    ];

```

and below this inside users template `add.ctp`

```auto
<?php
   echo $this->Form->create($user, array('type' => 'file'))."\n"; //I used for upload user avatar
   echo "Negara".$this->Form->control('countrie_id', array('type' => 'select', 'id' => 'jqueryNegara', 'label' => false, 'multiple' => false, 'disabled' => 'disabled', 'class' => 'red', 'options' => $countries, 'empty' => true, 'style' => 'width:200px;'))."\n"; //this normal works and display country with select options
   echo "Provinsi".$this->Form->control('province_id', array('type' => 'select', 'id' => 'jqueryProvinsi', 'label' => false, 'multiple' => false, 'disabled' => 'disabled', 'class' => 'red', 'options' => $provinces, 'empty' => true, 'style' => 'width:200px;'))."\n"; //this normal works and display province with select options
   echo $this->Form->button('TAMBAH', array('type' => 'submit', 'class' => 'submit', 'id' => 'Tambah'))."\n";
   echo $this->Form->end()."\n";
?>

```

and this below screenshoot users Template `index.ctp`  
one and more fields success save but one and more doesn’t save

 ![UsersFailedSaved](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/c/cdbe8a644db67c2a1bc30fc43bccd7211340347a.png)

I hope someone help me, good night with coffee

---

<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 28, 2020, 6:40pm UTC](https://discourse.cakephp.org/t/success-save-but-one-or-more-field-didnt-saved/8303/2 "2020-08-28T18:40:40Z")

</div>

Did you add those fields recently and then not clear your ORM cache before running this?

---

<div class="post-metadata">

**Author:** ![arizzoye](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@arizzoye](https://discourse.cakephp.org/u/arizzoye)\
**Post date:** [August 29, 2020, 4:31am UTC](https://discourse.cakephp.org/t/success-save-but-one-or-more-field-didnt-saved/8303/3 "2020-08-29T04:31:14Z")

</div>

I didn’t use ORM cache, how to use it. If I’ve stuck again, I used `cake bake all` tha’t wasting time, and needed backup ctp and modified 😰

---

<div class="post-metadata">

**Author:** ![arizzoye](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@arizzoye](https://discourse.cakephp.org/u/arizzoye)\
**Post date:** [September 2, 2020, 4:12am UTC](https://discourse.cakephp.org/t/success-save-but-one-or-more-field-didnt-saved/8303/4 "2020-09-02T04:12:56Z")

</div>

@Zuluru good morning, I’ve found and fix above trouble, that used cake bake all, but attended sequence of foreignkey parts, if `countries hasMany users` then the first sequence to use cake bake all is `Countries table`. Thanx for your guide and help
