Okay so here's the general gist: I have 2 content types, video and product. Each video has products associated with it through node reference. A product can be joined to multiple videos. Upon import it saves the initial product just fine, but I want to check to see if the product exists upon upload, and if it does, then I need to add another node reference instead of adding an additional product. The code to select the product works great, however the node update code doesn't work. It doesn't throw any errors, but it doesn't add another reference, it copies over the initial reference (what I was trying to avoid). How do I preserve the original reference and just add additional ones? My field is set to unlimited, and I can go in through the admin interface and link products manually to multiple videos, so in that sense it works, but I need to do this programmatically. Thoughts/Ideas/Suggestions?

$result = $efq->entityCondition('entity_type', 'node')
  ->fieldCondition('field_product_id', 'value', $prodID, '=')
  ->execute();
if (!empty($result['node'])) {
	$nids = array_keys($result['node']);
	$node = node_load($nids[0]);
	$node->field_video['und'][0]['target_id'] = $node_id;
	node_save($node);
}
else
{
  //Add product node
}

Comments

nevets’s picture

How about instead of

	$node->field_video['und'][0]['target_id'] = $node_id;

trying

        $new = array('target_id' => $node_id);
	$node->field_video['und'][] = $new;
cfox612’s picture

Genius!!!! I've been wracking my brain trying so many "fixes" I lost count.

Thank you!