Entity Metadata Wrapper: Setting User Reference Problem

How do I set a user reference value from the reference module using an entity metadata wrapper?

So Far

I have a form submit. It's creating an node with a user reference field. I can't work out what structure will submit the value.

First I tried submitting a user account (object), however this throws an awful error.

global $user;
$ewrapper-&gt;field_user_permission-&gt;set($user);


I then tried submitting uid, however it said it was expecting an array not a string.

$ewrapper-&gt;field_user_permission-&gt;set($user-&gt;uid);


I then tried creating a custom array based on printing out the array of a field that was already set.



$user_perm = array (
  'uid'    =&gt; $account-&gt;uid,
  'access' =&gt; TRUE,
);

 $ewrapper-&gt;field_user_permission-&gt;set($user_perm);


But that printed out another horrible error. What should I be using to submit the user reference?

 PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'uid' for column 'delta' at row 1: INSERT INTO {field_data_field_user_permission} (entity_type, entity_id, revision_id, bundle, delta, language, field_user_permission_uid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6), (:db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13); Array ( [:db_insert_placeholder_0] =&gt; node [:db_insert_placeholder_1] =&gt; 246 [:db_insert_placeholder_2] =&gt; 246      [:db_insert_placeholder_3] =&gt; contact_details [:db_insert_placeholder_4] =&gt; uid [:db_insert_placeholder_5] =&gt; und [:db_insert_placeholder_6] =&gt; 182 [:db_insert_placeholder_7] =&gt; node [:db_insert_placeholder_8] =&gt; 246 [:db_insert_placeholder_9] =&gt; 246 [:db_insert_placeholder_10] =&gt; contact_details [:db_insert_placeholder_11] =&gt; access [:db_insert_placeholder_12] =&gt; und [:db_insert_placeholder_13] =&gt; 1 ) in field_sql_storage_field_storage_write() (line 451 of C:\XAMPP\htdocs\drupal\modules\field\modules\field_sql_storage\field_sql_storage.module).


EDIT

New error for creating a new level:

$user_perm[] = array (
  'uid'    =&gt; $account-&gt;uid,
  'access' =&gt; TRUE,
);

$ewrapper-&gt;field_user_permission-&gt;set($user_perm);

PDOException: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn't match value count at row 1: INSERT INTO {field_data_field_user_permission} (entity_type, entity_id, revision_id, bundle, delta, language, field_user_permission_uid) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6_uid, :db_insert_placeholder_6_access); Array ( [:db_insert_placeholder_0] =&gt; node [:db_insert_placeholder_1] =&gt; 253 [:db_insert_placeholder_2] =&gt; 253 [:db_insert_placeholder_3] =&gt; contact_details [:db_insert_placeholder_4] =&gt; 0 [:db_insert_placeholder_5] =&gt; und [:db_insert_placeholder_6_uid] =&gt; 190 [:db_insert_placeholder_6_access] =&gt; 1 ) in field_sql_storage_field_storage_write() (line 451 of C:\XAMPP\htdocs\drupal\modules\field\modules\field_sql_storage\field_sql_storage.module).
Looks like Drupal is trying to set the delta column to the string "uid", which suggests you need another level in your array:

$user_perm[] = array (
  'uid'    =&gt; $account-&gt;uid,
  'access' =&gt; TRUE,
);

$ewrapper-&gt;field_user_permission-&gt;set($user_perm);