I have this function and have some problems I dont understand
it throws the above error
The print_r($this->orderItems); prints out an array of objects but then inside the foreach loop its not present the print_r($orderItem); prints out ‘a2’ ?
and the the next line $orderItem->orderid = $this->id; throws the error.
What am I missing here ??
protected function afterSave() {
parent::afterSave();
print_r($this->orderItems);
foreach($this->orderItems as $orderItem) {
//print_r($orderItem);
//exit();
$orderItem->orderid = $this->id;
$orderItem->save();
}
//return parent::afterSave();
}
Ok this is how it is done it is new records being created first I create an Order object and then add orderitems to it, teh error is thrown when I am trying to save the order object, and also the aftersave function belong to the order class.
So no data is actually coming from the database in the above example just new objects I am trying to save to the database.