How to disable defaultScope from other models

I have this multi tenant app. A project has a status and a manager. Status (fk) has no default scope. Model ‘project’ and model ‘person’(manager) have defaultScopes like:


	public function defaultScope()

	{

		return array(

			'condition'=>'tenant_id='.Yii::App()->user->tenantId,

		);

	}

}

I have a CgridView which displays project name with the manager and the status like:

Model:

Declare variables:


class Project extends CActiveRecord

{

        

        public $status_list;

        public $manager_list;

Rules:


	public function rules()

	{

		

			array('actual_start_date, actual_end_date, status_list, manager_list', 'safe', 'on'=>'search'),

	

Relations:


	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'person' => array(self::BELONGS_TO, 'Person', 'person_id'),

			'projectStatus' => array(self::BELONGS_TO, 'ProjectStatus', 'project_status_id'),

/code]


[code]	public function search()

	{

		// Warning: Please modify the following code to remove attributes that

		// should not be searched.


		$criteria=new CDbCriteria;

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

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

                .........

		$criteria->compare('user_updated',$this->user_updated);

                $criteria->compare('projectStatus.name',$this->status_list, true);                




in the View - CgridView, i want drop downs lists so that users can pick a value filter:


               array( 

                        'name'=>'manager_list', 

                        'header'=>'Manager',

                        'filter'=>CHtml::listData(Person::model()->findAll(), 'fullname', 'fullname'),

                        'value'=>'$data->person->fullname'

                ),    

                 array( 

                        'name'=>'status_list', 

                        'header'=>'Status',

                        'filter'=>CHtml::listData(ProjectStatus::model()->findAll(), 'name', 'name'),

                        'value'=>'$data->projectStatus->name'

        

Problem is that i get an SQL statement error. I suspect that it is the 2 default scopes. Here is the error message:

Q’s

How can i get around this?

Do you see anything wrong with the code?

How do you disable a default scope from another model?

Not really "wrong" but as the SQL error says, ambiguous, because in your case you have more than one column with the same name (tenant_id) in the resulting SQL query.

Disambiguating is possible even in your scopes. See here (there also other posts on the forum):

http://www.yiiframework.com/forum/index.php/topic/17595-column-disambiguation-on-named-scopes/