与 findAll() 不相等的条件

Not equal condition with findAll()

我正在尝试使用以下代码

从 table 中提取记录
$userId = Yii::$app->user->id;
$lists = PromoLists::findAll(['user_id' => $userId, 'list_type' => 'custom']);

输出如下查询

select * from promo_lists where user_id ='$userId' and list_type='custom'

但是我无法在文档中找到任何可以帮助我在以下条件下实现它的内容。

select * from promo_lists where user_id ='$userId' and list_type='custom' and status!='deleted'

因为状态是一个 ENUM 字段并且有 4 个不同的状态

'active','pending','rejected','deleted'

目前我使用了以下方法

PromoLists::findAll(['user_id' => $userId, 'list_type' => 'custom', 'status'=>['active','pending','rejected']]);

输出以下查询

select * from promo_lists where user_id ='$userId' and list_type='custom' and status in ('active','pending','rejected')

它以某种方式实现了相同的目的,但每次在 table 列 status.

中添加新状态类型时都需要编辑此查询

我知道我可以使用 PromoLists::find()->where()->andWhere()->all()

但如何使用 findAll().

!= / <> 运算符进行核对

在条件中使用运算符格式

http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html#operator-format

PromoLists::find()
    ->andWhere([
        'user_id' => $userId,
        'list_type' => 'custom',
        ['!=', 'status', 'deleted']
    ])
    ->all();

就是这样:

PromoLists::find()->where(['and',
    [
        'user_id' => $userId, 
        'list_type' => 'custom',
    ],
    ['<>', 'status', 'deleted'],
])->all();