2011-04-05 56 views
1

我使用NestedSet行爲與教條1.2.4與Zend框架 但我有一些困難時,插入已保存的根節點的子節點 該Doctrine文檔顯示創建根+孩子的情況下在同一頁面 而在我的案件的元素,根已經創建並保存,我需要插入它Manipulate Doctrine NestedSet樹

這裏一個孩子就是一個例子

 //// reading old order info 
     $order = new Order(); 
     $orderInfo = $order->read($order_id); 
     $oldOrder = $orderInfo->toArray(); 
     $oldOrder = $oldOrder[0]; 
     //// building the new order information 
     $renew = new Orders(); 
     $renew->domain_id = (int) $oldOrder["domain_id"]; 
     $renew->auth_id  = (int) $oldOrder["auth_id"]; 
     $renew->price  =   $oldOrder["price"]; 
     $renew->type  = (string) $oldOrder["type"]; 
     $renew->timestamp = $oldOrder["timestamp"]; 
     $renew->save(); 
     //// doctrine throwing an error here complaining the $orderInfo should be an instance of Doctrine_Record while its now an instance of Doctrine_Collection 
     $aa = $renew->getNode()->insertAsLastChildOf($orderInfo); 

我真的不知道該怎麼從數據庫中檢索訂單以及如何將其轉換爲doctr ine_record或有其他方式來操縱這個nestedset
任何建議,將不勝感激

回答

1

試試這個:

// This will retrieve the 'parent' record 
$orderInfo = Doctrine_Core::getTable('Order')->find($order_id); 

// building the new order information 
$renew = new Orders(); 
$renew->domain_id = (int) $oldOrder["domain_id"]; 
$renew->auth_id  = (int) $oldOrder["auth_id"]; 
$renew->price  =   $oldOrder["price"]; 
$renew->type  = (string) $oldOrder["type"]; 
$renew->timestamp = $oldOrder["timestamp"]; 
$renew->save(); 

$renew->getNode()->insertAsLastChildOf($orderInfo); 

這應該讓父節點的學說記錄,你可以用它來插入子作爲的最後一個孩子。