Open derekisbusy opened 9 years ago
That mean need rewrite getDbConnection()?
No. Just add it to the class declaration. This would correspond to the component in the main config...
'components'=>array(
// ...
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=yii',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'test',
),
// second db connection...
'db2'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
Where the components key in the config array is the FullModelCode connectionId.
In http://www.yiiframework.com/doc/api/1.1/CActiveRecord#getDbConnection-detail described: "You may override this method if you want to use a different database connection."
@derekisbusy I also agree to @uldisn, you should implement the dbConnection in the model as described in the Yii guide. You can specify a base class in the model generator and set the connection there, so you have only one place where you'd have to add the configuration - you may also use values from the config.
Please let me know if this solves the issue for you.
You have to add...
to the FullModelCode class.