0
votes

I am working on a custom drupal module that would change a node's node reference field value dynamically if a user clicks on an AJAX button.

In my callback function I could load the two nodes, A and B, where A has a node reference CCK field named 'foobar'.

How can I set edit and save this field? This is my attempt, but if I refresh the node, the field doesn't get updated.

$A_node = node_load($a_nid);
$B_node = node_load($b_nid);
$A_node->field_foobar[0]['nid'] = $b_nid;
node_save($A_node);
2

2 Answers

1
votes

Save the node using the vid as mentioned here or you can also if it is a cache problem as mentioned here.

1
votes

To save CCK fields, you need to call more than one function to save the complete node.

content_presave($node);
node_save($node);
content_insert($node);

Try this you might get all data inserted into database.