Activedataprovider Query with orWhere

I have the following sql query which I am trying to rebuild with ActiveDataProvider but with no success.


Select * from LeadDetail

Where Date Between '2015-09-01' AND '2015-09-30' And Name = 'Admin' AND (Price IS NULL OR (Purchase_Date IS NULL OR Purchase_Date= '')))

I tried with the following query but it does not create the proper OR nested grouping.


$dataProvider = new ActiveDataProvider([


            'query' => LeadDetail::find()

            ->andwhere(['between','Date',$start_date,$end_date])

            ->andwhere(['=','Name',Yii::$app->user->identity->username])

            ->andwhere(['is', 'Price', NULL]) 

            ->orwhere(['is', 'Purchase_Date', 'null'])

            ->orwhere(['=', 'Purchase_Date', ''])

How can I properly create nested OR??

I would combine all. Test this:




LeadDetail::find()->where([

    'and',

    ['between', 'Date', $start_date, $end_date],

    ['Name' => Yii::$app->user->identity->username],

    [

        'or',

        ['Price' => null],

        ['Purchase_Date' => null],

        ['Purchase_Date' => ''],

    ],

])



1 Like

Thanks a lot. It Works

Why don’t you use SqlDataProvider?

Look this good guide:

There are many functionalities i wanted to apply to my gridview which I thought was only possible using model and activedataprovider.

Thanks for the suggestion. I have been using SqlDataProvider in Yii 1.1x