Support for named models allowing separate scoped criteria

See my post here for need:

My solution is to implement named models as follows:

in CActiveRecord

	public static function namedModel($modelName)



			return self::$_models[$modelName];



			$currentModel = static::model();			

			$className = get_class($currentModel);						

			self::$_models[$className] = null;

			$newModel = self::model($className);

			self::$_models[$className] = $currentModel;

			self::$_models[$modelName] = $newModel;

			return $newModel;



In my controller:

$activeUsers = new CActiveDataProvider(User::namedModel('a')->whereActive(1));

$inactiveUsers = new CActiveDataProvider(User::namedModel('b')->whereActive(0));

Thoughts? I think having named models would provide a lot of value to the idea of scopes.


A very nice idea but I couldn’t fit it with my needs. Also hard to be maintained when the framework is updated.

I prefer to make a new model class that extends the base defined model.