Answers.Body: <p>User queries by default will only return active users, not pending or suspended ones.</p>
  
  <p>To include suspended users, change this line:</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>$user = $entry-&gt;user-&gt;one();
  </code></pre>
  
  <p>to this:</p>
  
  <pre class="lang-php prettyprint-override"><code>$user = $entry-&gt;user-&gt;status(['active', 'suspended'])-&gt;one();
  </code></pre>
  
  <p>Or if you want to include pending users as well (users who haven’t activated their account yet), you can do this:</p>
  
  <pre class="lang-php prettyprint-override"><code>$user = $entry-&gt;user-&gt;anyStatus()-&gt;one();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-06T17:31:34.367Z
Answers.Text: This did the trick! thanks! (spelling is hard)
Answers.UserDisplayName: Rick Kukiela
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-06T17:28:09.457Z
Answers.LastActivityDate: 2019-08-06T17:28:09.457Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I have a channel in which each channel entry has a "users" field type that is limited to one user. My code below works fine when the user is not suspended, however if I suspend the user, the then <code>$entry-&gt;user</code> field is null rather than set to the array of one user like its normally set to.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>        // do criteria code to get pending transfers from patients channel
      $account = $userIdentity-&gt;getFieldValue('account')-&gt;first();
      $entryQuery = Entry::find()
          -&gt;section('networkAssets')
          -&gt;relatedTo(['targetElement' =&gt; $account, "field" =&gt; "account"])
          -&gt;orderBy('title asc');
  
  
      // Execute the query and get the results
      $entries = $entryQuery-&gt;anyStatus()-&gt;all();
      $assets = [];
      foreach($entries as $entry) {
          $user = $entry-&gt;user-&gt;one();
          $assets[] = [
              'id' =&gt; $entry-&gt;id,
              'slug' =&gt; $entry-&gt;slug,
              'title' =&gt; $entry-&gt;title,
              'email' =&gt; $user-&gt;email,
              'first_name' =&gt; $user-&gt;firstName,
              'last_name' =&gt; $user-&gt;lastName,
              'address1' =&gt; $entry-&gt;address1,
              'address2' =&gt; $entry-&gt;address2,
              'state_province' =&gt; $entry-&gt;stateProvince,
              'city' =&gt; $entry-&gt;city,
              'postal_code' =&gt; $entry-&gt;postalCode,
              'country' =&gt; $entry-&gt;country,
              'username' =&gt; $user-&gt;username,
              'password' =&gt; '',
              'status' =&gt; $user-&gt;getStatus(),
              'date_created' =&gt; $entry-&gt;dateCreated-&gt;format('m/d/Y') . "&lt;br&gt;" . $entry-&gt;dateCreated-&gt;format('H:i:s T'),
              'last_login' =&gt; $user-&gt;lastLoginDate ? $user-&gt;lastLoginDate-&gt;format('m/d/Y') . "&lt;br&gt;" . $user-&gt;lastLoginDate-&gt;format('H:i:s T') : 'Never',
              'phone' =&gt; $entry-&gt;phoneNumber
          ];
      }
  
      return $assets;
  </code></pre>
  
  <p>You can see in the <code>foreach</code> loop that Im getting the user from the looped entry result and storing it in a <code>$user</code> variable.</p>
  
  <p>When I try to use <code>$user</code> I get a notice because $user is null.</p>
  
  <p><strong>How can I force this code to return the linked user in the user field even  when the user is suspended?</strong></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-08-06T17:22:31.083Z
Comments.Text: The `->anyStatus()->` was me just trying things to get this to work...
Comments.UserDisplayName: Rick Kukiela
Tags: <plugin-development><craft3><entries>
Title: Entry element query missing user field data when user is suspended
ThreadText: # Entry element query missing user field data when user is suspended
  
  (Asked by: username_0 on 2019-08-06)
  
  I have a channel in which each channel entry has a "users" field type that is limited to one user. My code below works fine when the user is not suspended, however if I suspend the user, the then `$entry->user` field is null rather than set to the array of one user like its normally set to.
  
  Here is my code:
  
  ```
          // do criteria code to get pending transfers from patients channel
      $account = $userIdentity->getFieldValue('account')->first();
      $entryQuery = Entry::find()
          ->section('networkAssets')
          ->relatedTo(['targetElement' => $account, "field" => "account"])
          ->orderBy('title asc');
  
      // Execute the query and get the results
      $entries = $entryQuery->anyStatus()->all();
      $assets = [];
      foreach($entries as $entry) {
          $user = $entry->user->one();
          $assets[] = [
              'id' => $entry->id,
              'slug' => $entry->slug,
              'title' => $entry->title,
              'email' => $user->email,
              'first_name' => $user->firstName,
              'last_name' => $user->lastName,
              'address1' => $entry->address1,
              'address2' => $entry->address2,
              'state_province' => $entry->stateProvince,
              'city' => $entry->city,
              'postal_code' => $entry->postalCode,
              'country' => $entry->country,
              'username' => $user->username,
              'password' => '',
              'status' => $user->getStatus(),
              'date_created' => $entry->dateCreated->format('m/d/Y') . "<br>" . $entry->dateCreated->format('H:i:s T'),
              'last_login' => $user->lastLoginDate ? $user->lastLoginDate->format('m/d/Y') . "<br>" . $user->lastLoginDate->format('H:i:s T') : 'Never',
              'phone' => $entry->phoneNumber
          ];
      }
  
      return $assets;
  
  ```
  
  You can see in the `foreach` loop that Im getting the user from the looped entry result and storing it in a `$user` variable.
  
  When I try to use `$user` I get a notice because $user is null.
  
  **How can I force this code to return the linked user in the user field even when the user is suspended?**
  
  **Tags:** plugin-development, craft3, entries
  
  > **Comments:**
  > **username_0**: The `->anyStatus()->` was me just trying things to get this to work...  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-08-06. Score: 3 | Accepted answer
  
  User queries by default will only return active users, not pending or suspended ones.
  
  To include suspended users, change this line:
  
  ```php
  $user = $entry->user->one();
  
  ```
  
  to this:
  
  ```php
  $user = $entry->user->status(['active', 'suspended'])->one();
  
  ```
  
  Or if you want to include pending users as well (users who haven’t activated their account yet), you can do this:
  
  ```php
  $user = $entry->user->anyStatus()->one();
  
  ```
  
  > **Comments:**
  > **username_0**: This did the trick! thanks! (spelling is hard)  
  
  ---
  
  