Use of named scopes in defaultScope

[color=#222222][font=Arial, sans-serif][size=4]As announced on the main page, Yii encourages [/size][/font][/color]DRY[color=#222222][font=Arial, sans-serif][size=4] design which is what I try to do when referencing defined named scopes in the defaultScope definition:[/size][/font][/color]




	/**

	 * @return array Default scope for this model.

	 */

	public function defaultScope() {


	    return array (

				'condition'=>$this->getTableAlias(false, false) .'.type_id=:kind',

				'params'=>array(':kind'=>self::TYPEID),


		        'scopes'=>array('users','active'),

		);

	}



Basically ‘users’ does the same thing as ‘condition’ and ‘params’ - find entries with the type_id that correspond to the user kind.

With ‘condition’ and ‘params’ things are working, but I would like to restrict the default scope a bit more using the conditions set by the ‘active’ scope, and at the same time get rid of the ‘condition’ and ‘params’ because the named scope ‘users’ does the same thing.

However, ‘scopes’ has no effect whatsoever on the search, while ‘condition’ and ‘params’ do have an effect.

When looking at some pieces of the code, it looks like the defaultScope be supporting the reference to named scopes, but in practice it does not.

The reason that I want to use the named scope for is of course the ‘DRY’ principle in conjunction with the fact that this ‘defaultScope’ is defined in a child class of its mother class where all kinds of named scopes are already defined.

The workaround is to not use ‘scopes’ and use only ‘condition’ and ‘params’. My goal in sharing this is to have your feedback on whether this should be possible, if I am doing something wrong to make it work, … . I think that it would be great if this could be available.

I am using Yii 1.1.10.

In looking through the Docs: It looks like ‘defaultScope’ is just a special name ‘named scope’ and may not be able to do what you were asking.

But I could be wrong :(