Yii2 - WHERE IN有活动记录

Sas*_*sha 13 yii2

是否有可能使WHERE IN条件具有活动记录?我正在阅读文档,但我找不到这种情况.我需要执行此查询并返回计数值.

这是我现在使用的方法:

public function static findProductsOnSale($ids)
    {
        return $this->find()->where(['product_id' => $ids])->count();
    }
Run Code Online (Sandbox Code Playgroud)

Ton*_*ony 29

至于在哪里()文档说:

['id'=> [1,2,3],'status'=> 2]生成(id IN(1,2,3))AND(status = 2)

所以你的方法应该是正确的.如果您想使用IN,那么您的代码应如下所示:

public function static findProductsOnSale($ids)
{
    return $this->find()->where(['in', 'product_id', $ids])->count();
}
Run Code Online (Sandbox Code Playgroud)