Answers.Body: <p>To mark this as answered, my solution was to use this code to get the current employee IDs regardless of status.</p>
  
  <pre><code>$employees   = $currentUser-&gt;employees-&gt;status('*')-&gt;ids();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-21T11:59:57.633Z
Answers.LastActivityDate: 2017-01-21T11:59:57.633Z
Answers.UserDisplayName: billythekid
Body: <p>I have this code to save a new user onto a userfield on another user:</p>
  
  <pre class="lang-php prettyprint-override"><code>    $employees   = $currentUser-&gt;employees-&gt;ids();
      $employees[] = $employee-&gt;id;
      $currentUser-&gt;getContent()-&gt;setAttributes(['employees' =&gt; $employees]);
      if (!craft()-&gt;users-&gt;saveUser($currentUser))
      {
          Craft::dd($currentUser-&gt;getErrors());
      }
  </code></pre>
  
  <p>Which works fine, however if there's a pending user in the employees field it's not returned in the ids() array. How do I get <em>all</em> user ids from the employees field, not just active users?</p>
  
  <p><strong>Edit:</strong> got it:</p>
  
  <pre><code>    $employees   = $currentUser-&gt;employees-&gt;status('*')-&gt;ids();
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-01-20T20:24:01.023Z
Comments.Text: Can you add your solution as an official answer, @billythekid?
Comments.UserDisplayName: Brad Bell
Tags: <plugin-development><users><field>
Title: Add a user to a userfield when there's a pending user on there
ThreadText: # Add a user to a userfield when there's a pending user on there
  
  (Asked by: username_0 on 2017-01-20)
  
  I have this code to save a new user onto a userfield on another user:
  
  ```php
      $employees   = $currentUser->employees->ids();
      $employees[] = $employee->id;
      $currentUser->getContent()->setAttributes(['employees' => $employees]);
      if (!craft()->users->saveUser($currentUser))
      {
          Craft::dd($currentUser->getErrors());
      }
  
  ```
  
  Which works fine, however if there's a pending user in the employees field it's not returned in the ids() array. How do I get *all* user ids from the employees field, not just active users?
  
  **Edit:** got it:
  
  ```
      $employees   = $currentUser->employees->status('*')->ids();
  
  ```
  
  **Tags:** plugin-development, users, field
  
  > **Comments:**
  > **username_1**: Can you add your solution as an official answer, @username_0?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-01-21. Score: 1 | Accepted answer
  
  To mark this as answered, my solution was to use this code to get the current employee IDs regardless of status.
  
  ```
  $employees   = $currentUser->employees->status('*')->ids();
  
  ```
  
  
  ---
  
  