set a entity reference field programmatically
In case entityreference prepopulate is not a viable option, I always use an EntityMetadataWrapper to set field values.

function mymodule_node_ref_presave($node_ref) {
    global $user;
    $query = new EntityFieldQuery();
    $query-&gt;entityCondition('entity_type', 'node_ref');
    $query-&gt;fieldCondition('cmp_ref', 'target_id', $user-&gt;uid);
    $result = $query-&gt;execute();
    // A more efficient way to grab entity ids from a EFQ
    if($result['node_ref']){
      $ref_ids = array_keys($result['node_ref']);
    }
    if ($ref_ids){
      // Load the entity w/ metadata wrapper to set field more transparently
      $node_ref_wrapper = entity_metadata_wrapper('node', $node_ref);
      $node_ref_wrapper-&gt;entity_reference_field-&gt;set($ref_ids);
      // Because this operation is going to execute a save anyways,
      // we don't need to do $wrapper-&gt;save()
    }
}