Hi,
I am having trouble creating new records that are in a BelongsTo association
Two tables: Users and Customers. User = [id, username, customer_id]
Customer = [id, firstname, lastname]
I have a form where someone can enter username, firstname, and lastname. I
want to create a new Customer record and related User record.
Starting from the baked code in CustomersController 'add' function I have
```
$customer = $this->Customers->newEntity();
if ($this->request->is('post')) {
$customer = $this->Customers->patchEntity($customer,
$this->request->data);
$cr = $this->Customers->save($customer)
if ($cr) {
// Trying to create User:
$user = $this->Customers->Users->newEntity();
$user = $this->Customers->Users->patchEntity($user,
$this->request->data);
$user = $this->Customers->Users=>patchEntity($user,
['customer_id' => $cr->get('id')]);
if ($this->Customers->Users->save($user)) {
// save just returns false.
$this->Flash->success('The customer has been saved.');
return $this->redirect(['action' => 'index']);
}
} else {
$this->Flash->error('The customer could not be saved.
Please, try again.');
}
}
```
I've checked for validation errors and there are none. Am I going about
this wrong??
This is the tail of the SQL log with or without the "save()" call. It's
like save is not even tried. Any ideas what is going on here?
SHOW FULL COLUMNS FROM `users`61SHOW INDEXES FROM `users`20SELECT * FROM
information_schema.key_column_usage AS kcu INNER JOIN
information_schema.referential_constraints AS rc ON (kcu.CONSTRAINT_NAME =
rc.CONSTRAINT_NAME) WHERE kcu.TABLE_SCHEMA = 'hotdogs_data' AND
kcu.TABLE_NAME = 'users' and rc.TABLE_NAME = 'users'00SHOW TABLE STATUS
WHERE Name = 'users'
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.