How to programmatically create file entity reference on entity Example with "normal" entity reference.

$node = node_load($nid);
$node-&gt;field_reference = array(
  $node-&gt;language =&gt; array(0 =&gt; array(
    'target_id' =&gt; $other_nid,
  ))
);
node_save($node);


Now I want to do the same, but on a File entity field instead.
Examining an attached file with devel, the field looks mostly like a plain

$file = file_load($fid);


object, but there's some more data on it, so I'm guessing I will hit problems down the road if I just stick the $file on to the ref, instead of figuring out the proper API call.
The file entity module wraps around the core file field, which defines only three field columns that you need to worry about providing:


fid (file id)
display (boolean indicating if the file is displayed or not)
description (self-explanatory)


You can safely ignore any other values that you find on the field as they'll be discarded anyway when it comes to committing the field data.

If I remember rightly it's the core file module that adds the extra data to the field, which is essentially the file object converted to an array. If you're seeing any other 'foreign' values in there they're probably coming from the file_entity_field_load() function.