I am using Cakephp 2.4.5. I have 2 tables with a one-to-many relationship. Table B belongs to Table A.
I want a controller in Table A that can save records in Table A and Table B. The controller code should be simple and looks like this;
public function add_tableA($id=null)
{
if ($this->request->is('post'))
{
$this->layout = null ;
$this->TableA->create();
$this->TableA->saveAll($this->request->data, array('deep' => true));
}
}
My problem comes when trying to send the right HTTP POST format to the controller.
I tried to HTTP POST the data format below but it fails.
data[TableA][field1] = field1_value
data[TableA][field2] = field2_value
data[TableB][field1] = field1_value
data[TableB][field2] = field2_value
Then, I try to HTTP POST the data format below, at least TableA fields are populated.
data[TableA][field1] = field1_value
data[TableA][field2] = field2_value
How should the HTTP POST data format look like if I want to create rows for both tables?
TableA hasMany TableB
. Do you have that in your model? – skywalker