Update field collection programatically - backend different to frontend I know there are other questions similar to this, but I'm having a specific problem. I'm trying to programmatically update a field collection (from it's fid only). This appears to work when printing out the values on the frontend, but when editing the node that the field collection is attached to, the fields within the collection are empty, but the collection itself is there.

// Unset and start afresh
unset($node-&gt;field_composition[LANGUAGE_NONE]);

foreach($fids as $fid){
  $comp = entity_load_single('field_collection_item', array($fid));
  $comp-&gt;field_chemical[LANGUAGE_NONE][0]['target_id'] = $id; // These values are derived elsewhere and are correct
  $comp-&gt;field_weight[LANGUAGE_NONE][0]['value'] = $value; // These values are derived elsewhere and are correct
  $comp-&gt;save(TRUE);
  $node-&gt;field_composition[LANGUAGE_NONE][] = array('value' =&gt; $comp-&gt;item_id);
}

node_save($node);


I assume the problem is to do with revisions - as the data is correctly saved somewhere - else it wouldn't appear on the front end. How to solve this?
Well, as always happens I found the answer just after I posted the question:

// Unset and start afresh
unset($node-&gt;field_composition[LANGUAGE_NONE]);

foreach($fids as $fid){
  $comp = entity_load_single('field_collection_item', array($fid));
  $comp-&gt;field_chemical[LANGUAGE_NONE][0]['target_id'] = $id; // These values are derived elsewhere and are correct
  $comp-&gt;field_weight[LANGUAGE_NONE][0]['value'] = $value; // These values are derived elsewhere and are correct
  $comp-&gt;save(TRUE);
  $node-&gt;field_composition[LANGUAGE_NONE][] = array(
    'value' =&gt; $comp-&gt;item_id,
    'revision_id' =&gt; $comp-&gt;revision_id // ADDED REVISION ID HERE!
  );
}

node_save($node);