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
  • 1
    Can you add your solution as an official answer, @billythekid?
    – Brad Bell
    Commented Jan 20, 2017 at 20:24

1 Answer 1

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();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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