简体   繁体   中英

CakePHP 3.3.0 not updating hasOne table

I have the following function:

public function edit($id = null)
{
    $resident = $this->Residents->get($id, [
        'contain' => [ 'ResidentGeneral' ]
    ]);
    if ($this->request->is(['patch', 'post', 'put'])) {
        $resident = $this->Residents->patchEntity($resident, $this->request->data);
        if ($this->Residents->save($resident)) {
            $this->Flash->success(__('The resident has been saved.'));
                return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error(__('The resident could not be saved. Please, try again.'));
        }
    }

    $titles = $this->Residents->ResidentGeneral->Titles->find('list', ['limit' => 200]);
    $sexes = $this->Residents->ResidentGeneral->Sexes->find('list', ['limit' => 200]);
    $maritalStatuses = $this->Residents->ResidentGeneral->MaritalStatuses->find('list', ['limit' => 200]);
    $rooms = $this->Residents->ResidentGeneral->Rooms->find('list', ['limit' => 200]);
    $nationalities = $this->Residents->ResidentGeneral->Nationalities->find('list', ['limit' => 200]);
    $ethnicOrigins = $this->Residents->ResidentGeneral->EthnicOrigins->find('list', ['limit' => 200]);

    $this->set(compact('resident', 'titles', 'sexes', 'maritalStatuses', 'rooms', 'nationalities', 'ethnicOrigins'));
    $this->set('_serialize', ['resident']);
}

The add function is identical with the exception of

     $resident = $this->Residents->get($id, [
        'contain' => [ 'ResidentGeneral' ]
    ]);

being instead

    $resident = $this->Residents->newEntity();

and $id = null missing from the top.

Now the add function will save to the database correctly and to the residentsGeneral table with out an issue however edit will not update, they are using the same form so all conventions are being kept.

The documentation on this states that patch and save both work one layer down with associations and even so add would not work if they didn't, also since the add function works, this means all models work correctly as well however this will not update any associated records in the table.

As you can probably see most of this code is baked so this is how the framework is intended to run.

Any help would be fantastic since I am one stage away from a broken PC.

它已经在master分支上修复,并将在cakephp 3.3.1中修复

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM