0

我已经成功地从数据库中删除了节点(我检查了它),但问题是节点引用字段中的 nid 不会消失。我该如何删除这个?这是我的代码,它不起作用

if($op == 'delete' && $node->type == 'person'){


    $id = $node->nid;



    $q=db_query("select nid from content_field_movie_cast where field_movie_cast_nid = '$id'"); //get all the movie ids that have the cast
    db_query("DELETE from content_field_movie_cast where field_movie_cast_nid = '$id' "); // delete all the entry for that cast in a all the movies it is involve

    while($result=db_fetch_array($q)){

    $node1=node_load($result['nid']);

                $ctr=0;
                $cnt=count($node1->field_movie_cast);

                while($ctr<$cnt){

                        if($node1->field_movie_cast[$ctr]['nid']==$id){

                        dpm($node1->field_movie_cast[$ctr]['nid']=0);

                        node_delete($nid);

                        }

                $ctr++;
                }


    db_query("update content_type_movie set field_movie_cast_count_value =field_movie_cast_count_value -1 where nid = '".$result['nid']."' ");


    }
    }

这里还有一张图片,我在谈论没有名字的 nid 是我要删除的那个

在此处输入图像描述

4

2 回答 2

0

自从我使用 node_ref 以来已经有一段时间了。和 D6,虽然我对你的方法有点困惑。您从数据库中删除了节点?这意味着您从 UI 中删除了节点或使用http://api.drupal.org/api/drupal/modules!node!node.module/function/node_delete/6,而不是直接在数据库中做奇怪的事情?

引用此节点的节点仍将存储 A -> B 引用。如果您编辑节点,它是否允许您保存它,通常它会要求。您删除不存在的参考。保存/预览前的 ID。

于 2013-03-20T09:35:04.120 回答
0

虽然我认为这种方法有点奇怪,但我将采用以下编程方法:

function hook_form_alter(&$form, &$form_state, $form_id){
    //dsm($form);
    unset($form['field_movie_cast']['und'][0]['nid']['#default_value']);
}

这是基于 D7 的,因此对于 D6,可能需要对代码稍作调整。

于 2013-03-20T11:27:15.107 回答