操作 Doctrine NestedSet 树

发布于 2024-10-30 15:08:15 字数 1104 浏览 0 评论 0原文

我正在 Zend 框架中使用具有原则 1.2.4 的 NestedSet 行为 但在插入已保存的根节点的子节点时遇到一些困难 Doctrine 文档展示了在同一页面上创建根元素 + 子元素的情况 在我的例子中,根已经创建并保存,我需要插入它的一个子项,

这是一个例子,

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

我真的不知道如何从数据库检索订单以及如何将其转换为doctrine_record或还有其他操作此嵌套集的方法
任何建议将不胜感激

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋风の叶未落 2024-11-06 15:08:15

试试这个:

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

这应该获得父节点的 Doctrine Record,您可以使用它来插入子节点作为最后一个子节点。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文