A
A
akula222016-02-08 21:35:56
Yii
akula22, 2016-02-08 21:35:56

How to insert another one in the dataprovider request?

There is such a request for gridview

$query = self::find()->where('
        user_id = :user_id AND sender_id != :user_id AND status != :status', 
        [
            'user_id' => Yii::$app->user->id,
            'status' => Pm::STATUS_DELETE,
        ])
        ->groupBy('sender_id')
        ->with(['profile']);

I need to insert another one into this query, I want to know if there is at least one record with status = 0
If there is, then I need to display the corresponding icon in the grid /
how can I insert another nested query here

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2016-02-09
@p0vidl0

First get the number of records with status = 0, and then conditionally add a column.

$zeroStatusCount = self::find()->where('
    user_id = :user_id AND sender_id != :user_id AND status = :status', 
    [
        'user_id' => Yii::$app->user->id,
        'status' => 0,
    ])
    ->groupBy('sender_id')
    ->count();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question