I do not understand why related entities are not working with cakephp, for example: I have an entity company, and this company has a user. In my view, the company values correctly put [$ company-> cnpj] and the values for user, I put through the relationship [$ company-> user-> name], but when saving the data, they are not persisted. Follow my controller.
public function add()
{
$empresa = $this->Empresas->newEntity();
$tableUser = TableRegistry::get("Users");
$user = $tableUser->newEntity();
$empresa->user = $user;
if ($this->request->is('post')) {
$empresa = $this->Empresas->patchEntity($empresa, $this->request->data, ['associated' => ['Users.User']]);
if ($this->Empresas->save($empresa,['associated' => ['User']])) {
$this->Flash->success(__('Sua empresa foi cadastrada com sucesso!'));
return $this->redirect(['controller' => 'Public', 'action' => 'boasvindas']);
} else {
$this->Flash->error(__("Ohh não! Houve um problema, por favor comunique-nos o quanto antes."));
}
}
$users = $this->Empresas->Users->find('list', ['limit' => 200]);
$this->set(compact('empresa', 'users'));
$this->set('_serialize', ['empresa']);
}
I do not know the $ this-> Business-> save ($ company, ['associated' => '' User ']]) is wrong. I would like some help.