开发者

Manipulate Doctrine NestedSet tree

I am using NestedSet behavior with doctrine 1.2.4 with Zend framework but i am having some difficulty when inserting a child node of already saved root node the 开发者_如何学编程Doctrine documentation showed the case of creating both root + child elements on the same page while in my case , the root is already created and saved and i need to insert a child of it

here is an example

        //// 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);

i don't really know how to retrieve the order from the db and how to convert it to doctrine_record or there is other ways to manipulate this nestedset

any suggestion would be appreciated


Try this:

// 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);

That should get a Doctrine Record of the parent node and you can use that to insert the child as the last child of.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜