如何在drupal 6中删除节点引用类型

时间:2013-03-19 15:59:04

标签: drupal

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

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是我要删除的那个

enter image description here

2 个答案:

答案 0 :(得分:0)

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

对该节点进行裁判的节点仍将具有A - &gt; B参考存储。如果您编辑节点,它允许您保存它,通常它会req。你要删除不存在的ref。保存/预览前的ID。

答案 1 :(得分:0)

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

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

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