You can customize gii tool and make it dynamically generate model such as
Yii::app()->getModule('ssgii')->SSGenModel($dynamictableName, $dynamicModelName);
public function SSGenModel($tableName, $modelName){
$_ccodeGen = $this->controllerMap;
$ccodeGen = new CCodeGenerator('', null);
$ccodeGen->codeModel = 'ssgii.generators.model.ModelCode';
$model=$ccodeGen->ssAutoGenModel($tableName, $modelName);
return ($model);
}
There still need some more updates to get it work. But from your requirement what I read, it seems not to be fit with your need.
You have expected much things to dynamic your relation, and it seems more further necessary things what Yii provides, you should have to comprehend around template knowledge. I can suggest the generator tool which help developer to build their own template source code, then you could read up your database structure and schema, etc and make any model template what you need.
http://www.codesmithtools.com/product/generator
I've used this tool in .NET and SQL SERVER, but it also supports on PHP and MYSQL
http://community.codesmithtools.com/support_forums/f/3/p/11630/44588.aspx