Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii2 + join query in ActiveDataProvider

This is my actual query -

$dataProvider = new ActiveDataProvider([
            'query' => UserProfile::find()->with(['user'])
        ]);

'status' field is exist in user table. So I want to filter data by where status != 0 but it fails.

I tried this -

1

$dataProvider = new ActiveDataProvider([
            'query' => UserProfile::find()->with(['user'])->where('user.status !=',0)
        ]);

2

$dataProvider = new ActiveDataProvider([
            'query' => UserProfile::find()->with(['user'])->where('<>','user.status',0)
        ]);

None of it works. please let me how its possible?

like image 884
Nisarg Avatar asked Oct 20 '22 02:10

Nisarg


1 Answers

You need change your $dataProvider code with this code.

$dataProvider = new ActiveDataProvider([
            'query' => UserProfile::find()->joinWith(['user(relation_name)'])->where(['<>','user.status',0])
        ]);
like image 135
GAMITG Avatar answered Oct 21 '22 21:10

GAMITG