我必須更新myModule中自定義代碼的一些nodereference字段。這有如下當被插入一個特定類型的新節點,所以我實現hook_node_insert要做:Drupal 7 node_save完整性約束違規
function myModule_node_insert($node){
$settings = _settings_forms_nodereference_fields($node->type);
$field = $settings['field'];
$language = field_language('node', $node, 'body');
$node->{$field}[$language][0]['nid'] = 408;
$node->{$field}[$language][1]['nid'] = 408;
$node->{$field}[$language][2]['nid'] = 408;
node_save($node);
}
然而,每一個我試圖創建一個新的節點時,我碰到下面的錯誤;
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '436' for key 'PRIMARY': INSERT INTO {node} (nid, vid, type, language, title, uid, status, created, changed, comment, promote, sticky, tnid, translate) VALUES ....
我發現這是因爲node_save功能,但是沒有它我的更改不會提交。
全陣列如下:
[field_event_form_s_] => Array
(
[und] => Array
(
[0] => Array
(
[nid] => 261
)
[1] => Array
(
[nid] => 262
)
[2] => Array
(
[nid] => 263
)
)
)
我真的會在這裏得到一些幫助,因爲我不知道如何着手。