Im使用Doctrine,我需要克隆一个对象。是否可以更改教义对象的类别?
数据库中的两个表具有相同的列,但其中一个存在积压订单,而另一个存在订单确认。可能不是最好的办法,但它们必须分开,因为在积压对象上某些外键不能满足。
所以,我需要从待办事项克隆一个对象并将其插入到当前的订单表中。但是,如果我克隆积压订单对象,它会将类设置为积压订单。
$backlog_orders = $this->Subscription_model->getBacklogOrders();
foreach($backlog_orders as $backlog_order){
$new_order = new Entities\NewOrder;
$new_order = clone $backlog_order;
//Do other stuff to new order
//At this point, I need to change the class of the object to NewOrder so that it will insert it into the correct table
echo get_class($order); // Outputs BacklogOrder
$this->Subscription_model->updateOrder($order); // Saves to DB
}
伟大的答案。尽管我认为教义自动处理主键。 $ new_order = new Entities \ NewOrder;只是为了表明我试图设置一个新的实体,但显然克隆会创建一个新的克隆类型的对象。 我一直在想,当我写这个问题时,这样做没什么意义。我决定通过另一种方法手动进行复制。我希望setAll()可以工作,但无济于事。 – JackalopeZero