Support for named models allowing separate scoped criteria

See my post here for need:

http://www.yiiframework.com/forum/index.php?/topic/17377-multiple-cactivedataprovider-in-one-view-for-the-same-model-scopes-applied-late/

My solution is to implement named models as follows:

in CActiveRecord




	public static function namedModel($modelName)

	{

		if(isset(self::$_models[$modelName]))

			return self::$_models[$modelName];

		else

		{

			$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.

Hi,

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.

Regards,

Paul