Hi Sean,
Thanks for getting back to me, the copying of the dataobject is the way i want to go as i have currently two forms one for header and then one for adding the details. i have tried the code below, without much success, and as ever no error messages it just doesn't seem to make the copy.
I notices when i printed the contents of the array is doesn't list the data for the attached has_many relation is that correct or would you expect that function to copy both the header and details fields and copy those to their respected dataobjects.
function doaddOrder(){
$quote = QuoteHeader::get()->byId(2)->toMap();
$order = new OrderHeader();
$order->update($quote);
//print_r($order);
$order->write();
// Controller::curr()->redirectBack();
}
class QuoteHeader extends DataObject {
public static $db = array(
'Seq' => 'Int',
'QuoteNum' => 'Varchar(20)',
'Date' => 'Date',
'ExpiryDate' => 'Date',
'QuoteBy' => 'Varchar(30)',
'Notes' => 'Text',
'Status' => 'Varchar(20)'
);
public static $has_many =array (
'QuoteDetails' => 'QuoteDetail'
);
----------------------
class QuoteDetail extends DataObject {
public static $db = array(
'PartNum' => 'Varchar()',
'Name' => 'Varchar()',
'Qty' => 'int',
'Price' => 'Currency',
'Total' => 'Currency'
);
public static $has_one =array (
'QuoteHeader' => 'QuoteHeader'
);
class OrderHeader extends DataObject {
public static $db = array(
'Seq' => 'Int',
'OrderNum' => 'Varchar(20)',
'Date' => 'Date',
'ExpiryDate' => 'Date',
'OrderBy' => 'Varchar(30)',
'Notes' => 'Text',
'Status' => 'Varchar(20)',
);
public static $has_many =array (
'OrderDetails' => 'OrderDetail'
);
-------------------------------
class OrderDetail extends DataObject {
public static $db = array(
'PartNum' => 'Varchar()',
'Name' => 'Varchar()',
'Qty' => 'int',
'Price' => 'Currency',
'Total' => 'Currency'
);
public static $has_one =array (
'OrderHeader' => 'OrderHeader'
);