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->field_user_permission->set($user);
I then tried submitting uid, however it said it was expecting an array not a string.
$ewrapper->field_user_permission->set($user->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' => $account->uid,
'access' => TRUE,
);
$ewrapper->field_user_permission->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] => node [:db_insert_placeholder_1] => 246 [:db_insert_placeholder_2] => 246 [:db_insert_placeholder_3] => contact_details [:db_insert_placeholder_4] => uid [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 182 [:db_insert_placeholder_7] => node [:db_insert_placeholder_8] => 246 [:db_insert_placeholder_9] => 246 [:db_insert_placeholder_10] => contact_details [:db_insert_placeholder_11] => access [:db_insert_placeholder_12] => und [:db_insert_placeholder_13] => 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' => $account->uid,
'access' => TRUE,
);
$ewrapper->field_user_permission->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] => node [:db_insert_placeholder_1] => 253 [:db_insert_placeholder_2] => 253 [:db_insert_placeholder_3] => contact_details [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6_uid] => 190 [:db_insert_placeholder_6_access] => 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).