Register here!

Forgot password?

ASK NEW QUESTION

Home Page » Active Record » MANY_MANY Criteria problem
0 Votes
Vote Con!

MANY_MANY Criteria problem

CRITERIAmany_manySELECT

hi.
I have many_many relation.
Categories & Articles.
Just now I want create data provider for CListVeiw Articles where category id =5;(e.g)
But my code gives all the Articles (( Please help!

  1.         $criteriaItem = new CDbCriteria();
  2.  
  3.         $criteriaItem->with = array(
  4.             'Categories' => array(
  5.                 'condition' => 'Categories.id = :cat_id',
  6.                 'params' => array(':cat_id' => $categoryID)
  7.             )
  8.         );
  9.  
  10.         $articleItems = new CActiveDataProvider('Article', array(
  11.             'criteria' => $criteriaItem,
  12.             'pagination' => array(
  13.                 'pageSize' => Y::param('blogItemSize', 5),
  14.                 'pageVar' => 'page',
  15.             ),
  16.         ));
        $criteriaItem = new CDbCriteria();

        $criteriaItem->with = array(
            'Categories' => array(
                'condition' => 'Categories.id = :cat_id',
                'params' => array(':cat_id' => $categoryID)
            )
        );

        $articleItems = new CActiveDataProvider('Article', array(
            'criteria' => $criteriaItem,
            'pagination' => array(
                'pageSize' => Y::param('blogItemSize', 5),
                'pageVar' => 'page',
            ),
        ));

Thanks all.

By eibrahimov in Active Record · Asked 390 days 23 hours 30 mins ago

Questions: 4 Accepted: 0 ( 0% ) | Reputation: 0

 

Answers (1)

  1. 0 votes

    You can try add ‘together’=>true

    By SpiLLeR · 370 days 19 hours 20 mins ago

    Questions: 0 Accepted: 0 ( 0% ) | Reputation: 0

© YiiAnswers.com 2011. All rights reserved.

Switch to our mobile site