1

I have this code to save a new user onto a userfield on another user:

    $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();
  • 1
    Can you add your solution as an official answer, @billythekid? – Brad Bell Jan 20 '17 at 20:24
1

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();
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.