How can I populate a user field via a plugin? I have a plugin that listens for the users.onSaveUser. So when users register, an account is created, and I am creating an entry that will contain extended profile information. I am attempting to create a user field on that newly created entry to relate the entry back to the user account.

MyPlugin.php

$entry = new EntryModel();
$entry-&gt;sectionId = 16;
$entry-&gt;typeId = 1;
$entry-&gt;enabled = false;
$entry-&gt;authorId = $user-&gt;id;

$entry-&gt;getContent()-&gt;title = craft()-&gt;request-&gt;getPost('firstName') . ' ' . craft()-&gt;request-&gt;getPost('lastName');

// userAccount is the handle of the user field.
$entry-&gt;setContent(['fields' =&gt; ['userAccount' =&gt; $user-&gt;id]]);  // nope.
$entry-&gt;setContentFromPost(['userAccount' =&gt; $user-&gt;id]);        // nope.

...

craft()-&gt;entries-&gt;saveEntry($entry);


Everything is coming across except the user field. I'm not sure what the field needs/is looking for to set it's value.
Relational fields are always stored as arrays, even if you are limiting them to only one entry so this should work:

$entry-&gt;setContentFromPost(['userAccount' =&gt; array($user-&gt;id)]);