0

How do I use the conditions "not exist" and "not in" in Yii2? I have a select with the list of users, but want to exclude users who are on the table "user_post"

User

id_user | username

User_post

id_user_post | id_post | id_user

 <?= $form->field($model, 'id_user')->dropDownList(
         ArrayHelper::map(User::find()

                ->all(),'id_user','username'),
        ['prompt' => 'Select User']
    ) ?>
Giest
  • 495
  • 1
  • 10
  • 21

1 Answers1

2

You can do it like below:

User::find()->where(['not in','user_id',[1,2,3]]);

Which returns Users with ID's not in [1,2,3]

Ali MasudianPour
  • 14,329
  • 3
  • 60
  • 62