我有2个节点:
项目具有对Bugs
的节点引用当我删除Bug时,这些节点引用仍然是孤立的。什么是清理它的最佳方法?
更新(这是我要做的)
function dc_project_management_node_delete($node)
{
if ($node->type == 'bug_request')
{
$bug_request_nid = $node->nid;
$milestone_ids = db_query('SELECT entity_id FROM {field_data_field_bugs_requests} WHERE field_bugs_requests_nid = :bug_request_nid', array(':bug_request_nid' => $bug_request_nid))->fetchCol();
$milestones = entity_load('field_collection_item', $milestone_ids);
foreach($milestones as $milestone)
{
for($k=0;$k<count($milestone->field_bugs_requests['und']);$k++)
{
if ($milestone->field_bugs_requests['und'][$k]['nid'] == $bug_request_nid)
{
unset($milestone->field_bugs_requests['und'][$k]);
}
}
entity_save('field_collection_item', $milestone);
}
}
}
答案 0 :(得分:1)
如果您想要排序的参照完整性(即删除项目时删除相关的错误),您可以这样做:
function mymodule_node_delete($node) {
if ($node->type == 'project') {
$bug_nids = array();
foreach ($node->field_bugs[LANGUAGE_NONE] as $bug) {
$bug_nids[] = $bug['nid'];
}
node_delete_multiple($bug_nids);
}
}