【问题标题】:Yii2: Use NOT EXISTS or NOT INYii2:使用 NOT EXISTS 或 NOT IN
【发布时间】:2016-02-11 12:29:08
【问题描述】:

如何在 Yii2 中使用条件“不存在”和“不在”? 我有一个用户列表的选择,但想排除表“user_post”上的用户

用户

id_user |用户名

用户帖子

id_user_post | id_post | id_user

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

                ->all(),'id_user','username'),
        ['prompt' => 'Select User']
    ) ?>

【问题讨论】:

    标签: sql yii2 not-exists notin


    【解决方案1】:

    你可以这样做:

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

    返回 Users 且 ID 不在 [1,2,3]

    【讨论】:

      猜你喜欢
      • 2018-01-08
      • 2015-07-06
      • 2014-12-29
      • 2014-07-18
      • 2021-10-02
      • 2015-10-13
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      相关资源
      最近更新 更多