pagination / filter problem

Using Yii 1.1.8 with Oracle 10g2

Can’t get pagination working correctly when CDbCriteria->together = true.

When I set together = true, all the filters work, but the pagination does not.

Setting together to null, false or not setting it at all, results in a working pagination, but filtering the data causes an "invalid identifier" SQL error to occur.

I have been browsing around online for an answer to this, but have been unsuccessful. Any ideas or "right direction" pointing is appreciated. If I am leaving anything important out, please let me know and I will do my best to include it.

The code I included below is for a class called ParcelLink and has a HAS_MANY relationship with "parcel". There is only one "parcel" per ParcelLink per year, and I am filtering on the year. Also, "PARCEL_NUMBER" is the only field I am using within the search that is owned directly by ParcelLink. Each of the related fields have setters and getters within the ParcelLink model.

    public function search()


        $criteria=new CDbCriteria;

        $criteria->with = array(











        $criteria->together = true;

        $criteria->compare('"t".PARCEL_NUMBER', $this->PARCEL_NUMBER, true);

        $criteria->compare('"parcel".HOUSE_NUMBER', $this->houseNumber, true);

        $criteria->compare('"parcel".PREFIX_DIRECTION', $this->streetDir, true);

        $criteria->compare('"parcel".STREET', $this->streetName, true);

        $criteria->compare('"parcel".STREET_TYPE', $this->streetType, true);

        $criteria->compare('"parcel".SUFFIX_DIRECTION', $this->streetSuffixDir,


        $criteria->compare('"parcel".UNIT', $this->streetUnit, true);


                $this->legalDescription, true);

        $criteria->compare('"subdivision".SUBDIVISION_CODE', $this->subdivision,


        $criteria->compare('"section".SECTION_NUMBER', $this->section,



                $this->township, false);


                $this->range, false);


                $this->ownerName, true);


                $this->ownerAddress1, true);


                $this->ownerAddress2, true);


                $this->ownerCity, true);


                $this->ownerState, true);


                $this->ownerZip, true);


                $this->ownerZip4, true);


                $this->ownerNumber, false);

        $criteria->compare('"parcel"."city".CITY_CODE', $this->cityCode, true);


                $this->taxDistrictCode, false);


                $this->homestead, true);


                $this->businessName, true);

        return new CActiveDataProvider(get_class($this), array(

			'criteria' => $criteria,


                'defaultOrder'=>'"t".PARCEL_NUMBER ASC',


            'pagination' => array(

                'pageSize' => 20,




I was going to link a screenshot of the search page, but I am not allowed to embed links in the forum at this time.

Will a plea of desperation help?

I have exactly the same problem, and it’s also driving me nuts.

I created a MANY_MANY relationship between my tables avh and tag using the intermediary table avh_tag.

public function relations()


    return array(

    	/* ... */

        'tags' => array(self::MANY_MANY, 'Tag', 'avh_tag(avh_id, tag_id)'),



Working fine, no problem. Now, for the index page, I need to filter on some tags. Here a simplified version of the filter code.

$criteria = new CDbCriteria;

$criteria->with = array('tags');


$criteria->together = true;

$dataProvider=new CActiveDataProvider('Avh', array(

        'criteria'=> $criteria,



If I remove the condition and set the together param to false, the pagination is working fine. If I keep the condition and remove the together, the request fails because of unknown column name. Ok. If I use exactly this code, no error is thrown, the filter is working fine… but the pagination goes completely crazy.

For example, for a pageSize of ten, I have a random number of items by page between 1 and 10. The total number of items is correct, and so is the total number of pages… except it’s calculated at ten items by page. The order of display is the one specified, and there is no fused items or other strange data. Problem exists both in JS and non-JS pagination.

Hi, GrendelTheory and Skarn,

I had just the same problem sometimes ago.

And my conclusion has been … it’s a pity but … it’s impossible to (1) filter by has_many(or many_many) relation and (2) paginate correctly AT THE SAME TIME using CActiveDataProvider in an ordinary way. There should be a decent work around, I hope, but I really don’t know by now. :(

Please check the answer from qiang.xue in the following link.


What Phillip has suggested in this thread could be a decent solution.

See the #3 post.

Thanks for your quick answer.

For lack of anything better, I solved my problem using the extra query solution. Hope one day someone will find a best way to go around this feature.