categoryFilter

i try to work with the filter relation option but the way it is working in de blog demo it’s not workingin for my project.

changeing the values of $withOption[‘categoryFilter’][‘params’][’:id’] = array(2, 4); doesn’t affect my results.

what is wrong with my filer option?

for an profilling export look here: http://pastebin.com/f1ac0c7d9

model:


    public function relations() {

        return array(

            'rCity' => array(self::BELONGS_TO, 'City', 'CityId'),

            'categoryFilter' => array(self::MANY_MANY, 'Category', 'DaytripCategory(DaytripId, CategoryId)',

                'joinType' => 'INNER JOIN',

                'condition' => 'categoryFilter.IdCategory=:id'

            ),

//            'rCategory' => array(self::MANY_MANY, 'Category', 'DaytripCategory(DaytripId, CategoryId)'),

//            'rTag' => array(self::MANY_MANY, 'Tag', 'DaytripTag(DaytripId, TagId)'),

//            'rTag2' => array(self::MANY_MANY, 'Tag', 'DaytripTag(DaytripId, TagId)',

//                'select' => array('GROUP_CONCAT(Tag SEPARATOR ", ") AS gTags'),

//                'group' => 'DaytripId'

//            )

        );

    }

    

    public function scopes()

    {

        return array(

            'distance' => array(

                'select' => array('Daytrip', new CDbExpression("geodistkm($this->Latitude, $this->Longitude, rCity.Latitude, rCity.Longitude) AS Distance")),

                'joinType' => 'INNER JOIN',

                'condition' => 'rCity.Latitude > 0 AND rCity.Longitude > 0',

                'order' => 'Distance ASC',

                'limit' => 100,

            )

        );

    }

controller:


    public function actionResults() {

        $withOption = array('rCity');

        $withOption['categoryFilter']['params'][':id'] = array(2, 4);

        

        if(Yii::app()->request->isPostRequest) {

            Daytrip::model()->mapToLatLon($_POST['yt0_x'], $_POST['yt0_y']);

            //echo Daytrip::model()->latitude;

            $daytrips = Daytrip::model()->distance()->with($withOption)->findAll();

            //print_r($daytrips);

        }

        $this->render('results', array('daytrips' => $daytrips));

    }

Database:

TABLE: Categories

FIELDS: IdCategory, Category

TABLE: DaytripCategory

FIELDS: DaytripId, CategoryID

TABLE: Daytrips

FIELDS: IdDaytrip, Daytrip, …, …

Your problem is similiar to mine —> here Please let me know if you resolve this.

$_POST[‘Categories’] is an array with values from checkboxes…

need some help?




    public function actionResults() {

        $withOption = array('rCity');

        $withOption['categoryFilter']['params'][':id'] = implode(",", $_POST['Categories']);

        

        if(Yii::app()->request->isPostRequest) {

            Daytrip::model()->mapToLatLon($_POST['yt0_x'], $_POST['yt0_y']);

            //echo Daytrip::model()->latitude;

            $daytrips = Daytrip::model()->distance()->with($withOption)->together()->findAll();

            //print_r($daytrips);

        }

        $this->render('results', array('daytrips' => $daytrips));

    }