Cumulative Scope

According to the reference, the CDbCriteria property ‘scopes’ is only valid for the find%() methods.

How could I use a cumulative scope?

For example, in a model of people, I have a scope to filter only those male and another scope to filter the boys, using the previous scope to enclose only the males? (this is a minimal example, my need was generated by very complex scopes).

It would be something like this:




public function scopes()

{

        return array(

            'male'=>array(

                'condition'=>"sex = 'M'",

            ),

            'boy'=>array(

                'scopes'=>'male',

                'condition'=>"age < 15",

            ),

        );

}



Use named scopes and method chain them??

http://www.yiiframework.com/doc/guide/1.1/en/database.ar#named-scopes

Yes, this is the direct solution.

But I would very much like a scope inherit the properties of another, not to be necessary to use chain of methods.

As I said earlier, I have complex scopes that are self related. If I have to use the chain, whenever needed to change my scope I have to scan multiple files to correct the chain of methods.

So I asked if anyone has an interesting solution to my problem.

Thanks for the reply!




class People extends CActiveRecord

{

    ......

	public function scopes()

	{

			return array(

				'male'=>array(

					'condition'=>"sex = 'M'",

				),

				'kid'=>array(

					'condition'=>"age < 15",

				),

			);

	}

	

	public function boy()

	{

			return $this->male()->kid();

	}

}



And then use chained method.


$boys = $model->boy()->findAll();

Maybe not the best or most elegant solution.

If anyone has another solution, please tell us.