How To Use Params In Cactiverecord->Relations() Method?

Hi guys, in CActiveRecord->relations() method we should create array like this:

public function relations()


   array (

      'varName'=>array('relationType', 'className', 'foreignKey', ...additional options),

      // so on



As you can see there are additional options that we can use ‘params’ keyword. with ‘params’ we can send parameters value to the query. I don’t know how to use it. can anyone make an example?

this is one simple example: providing additional join conditions

   array (

      'relation'=>array( self::HAS_MANY, 'RelatedModel', 'id_fk',

          'on'=>'relation.status = :status and relation.language = :language', //additional join condition

          'params'=>array( ':status'=>1, ':language'=>Yii::app()->language ), //query params for 'on' clause



thanks, but how to use url request value in ‘params’?


you can access them with Yii::app()->request->getParam(‘param_name’), so:


'params'=>array( ':status'=>Yii::app()->request->getParam('status')


but that is very bad design… relations should not be defined so that they relay on request params. you should rather introduce such params on action level, like:

$allRelated = $model->related;

$limitBasedOnGetParam = $model->related( array( 'condition'=>'related.status = :status', 'params'=>array( ':status'=>Yii::app()->request->getParam( 'status' ) ) );

Thank you redguy. :) Your help is complete and useful.