Hi GUys,
Im trying to save a record to a table aswell as an accociated record. The main table is called quotes and it has a hasmany link to the table quote_items. quote_items belongsto quote
When i try and save it saves the record in quote but does not save the record in quote_items .
Below is my quote add function
function add() {
if (!empty($this->data)) {
$this->Quote->create();
if ($this->Quote->saveAll($this->data)) {
$this->Session->setFlash(__('The Quote has been saved', true));
//$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Quote could not be saved. Please, try again.', true));
}
}
$this->Quote->recursive = 2;
$statuses = $this->Quote->Status->find('list');
$contacts = $this->Quote->Contact->find('list');
$this->set(compact('statuses', 'contacts'));
}
Quote view / form setup
<?php echo $form->create('Quote', array('action' => 'add'));?>
<fieldset>
<legend><?php __('Add Quote');?></legend>
<?php
echo $form->input('Quote.name');
echo $form->input('Quote.revision');
echo $form->input('Quote.status_id');
echo $form->input('Quote.contact_id');
echo $form->input('quote_item.product_id');
echo $form->input('quote_item.name');
echo $form->input('quote_item.price');
echo $form->input('quote_item.description');
echo $form->input('Quote.totalcost');
?>
</fieldset>
<?php echo $form->end('Submit');?>
Array that is returned when the form is submitted
Array (
[quote] => Array (
[name] => Test
[revision] => 1
[status_id] => 1
[contact_id] => 1
[totalcost] => 123
)
[quote_item] => Array (
[product_id] => 1
[name] => test
[price] => 123
[description] => tes 1234
)
)
This seems to follow exactly what is listed in the cakephp documentation so i cant work out why its not working - http://book.cakephp.org/view/84/Saving-Related-Model-Data-hasOne-hasMany-belongsTo
Thanks in advance