Why is limit not working in query builder?

I have the following query which returns results however it returns all results even though I have set the limit.


        $query = ProductItem::find()

        ->where(['brand_id' => $model->brand_id])

        ->limit(5);


         $dataProvider = new ActiveDataProvider([

            'query' => $query,

         ]);

Just a thought: Are you using a GridView or ListView to render the result? If so, check its pagination settings as that is going to override the limit you set in your query.

Thanks for the tip but it still didn’t work.

Ended up moving the query to my model and made the below code


    public function getRelatedProducts()

    {

        return ProductItem::find()

        ->limit(3)

        ->where(['brand_id' => $this->brand_id])

        ->andwhere(['NOT IN', 'id', $this->id])

        ->all();

    }



ActiveDataProvider returns all results with a specific query params and you can use it for the grid/list views.

you can set the pagesize that’s about it


    	

 		$dataProvider = new ActiveDataProvider([

            'query' => $query,

'pagination' => ['pageSize' =>12],

 		]);

use active query without the data provider…i had this problem with mongodb too