Prepare data before query

Where can I prepare data before performing query?

I precisely need to make a check:


if (!empty($this->id_district) AND $this->district->id_province != $this->id_province)

{

   $this->id_district = NULL;

}

This should be run every time before filtering data for grid widget. (Test if user earlier already picked district from different province).

In Yii 1 I had it placed in search method, but where to go with it now?

You can put it in your search model.

You can generate your search model using Gii tool

Thank you for help. I misunderstood search with query class, but finally figured it out.