SQL Dependency Injection for CActiveDataProvider

Hello,

I want to inject sql dependency for CActiveDataProvider. See below is my code returning CActiveDataProvider.




public function search() {

	$CADP = parent::search(); // Instance of CActiveDataProvider

	$CADP

        	->getCriteria()

        	->compare('id', $this->id)

        	->compare('application_code', $this->application_code, true)

        	->compare('first_name', $this->first_name)

        	->compare('last_name', $this->last_name)

        	->compare('date_of_birth', $this->date_of_birth, true)

        	->compare('designation', $this->designation, true)

        	->compare('company_name', $this->company_name, true)

        	->compare('email_id', $this->email_id, true)

        	->compare('phone_number', $this->phone_number, true)

        	->compare('heq_title_program_name', $this->heq_title_program_name, true)

        	->compare('heq_school_college_name', $this->heq_school_college_name, true)

        	->compare('heq_year_of_passing_out', $this->heq_year_of_passing_out)

        	->compare('total_experience_months', $this->total_experience_months)

        	->compare('work_history_current_organization', $this->work_history_current_organization, true)

        	->compare('work_history_current_domain_areas', $this->work_history_current_domain_areas, true)

        	->compare('work_history_current_tenure', $this->work_history_current_tenure)

        	->compare('work_history_current_work_location', $this->work_history_current_work_location, true)

        	->compare('registration_date', $this->registration_date, true)

        	->compare('final_submission_date', $this->final_submission_date, true)

        	->compare('approved_by', $this->approved_by)

        	->compare('approved_on', $this->approved_on)

        	->compare('approved', self::STATUS_ON_HOLD)

        	->compare('active', 1/* $this->active */)

        	->compare('deleted', 0/* $this->deleted */)

	;


	$CADP->sort = array(

    	'defaultOrder' => '`t`.`final_submission_date` DESC',

	);


	return $CADP;

}



Now, How can I inject dependency.

Normally I use as:




$model = SomeModel::model()->cache($dependency, 100)->findAll();



But how in this condition!

Instead of using the parent’s search() method you could create the CActiveDataProvider by yourself via


$CADP = new CActiveDataProvider(self::model()->cache(1000,$dependency));

....

....

I added this:




public function search() {

	$CADP = parent::search(); // Instance of CActiveDataProvider

	...


	$CADP->sort = array(

    	'defaultOrder' => '`t`.`final_submission_date` DESC',

	);


	/* Added Dependency */

	$dependency = new CDbCacheDependency("SELECT MAX(`final_submission_date`) FROM " . $this->tableName());

	$CADP->model->cache(1000, $dependency);


	return $CADP;

}



Will this work exactly what I want!

Other question: Does it work? :) Because I think it should. You could use CWebLogRoute to log tracing messages because Yii will log everything regarding caching. You would see if it works there.

Let me check!

By the way.

Thanks a lot