MultiActiveRecord

Support for multiple databases in your models, also comes with a gii generator template to create models that belongs to other databases

how to use:




class MyModel extends MultiActiveRecord{

   //my methods

  function connectionId(){

  	return 'my_db';

  }

}



and in your config


'components'=>array(

//main db configuration

 	'db'=>array('..'),

 	//connection my_db

 	'my_db'=>array(

      	'class'=>'CDbConnection',

      	'connectionString'=>'mysql:host=localhost;dbName=my_db',

      	'username'=>'mySUsername',

      	'password'=>'myPassword'

 	),

 	//you can define other connections also

),

),

Detailed explanation here: extension link

Complete change in the code, check the extension link for more details

Moved to "Extensions" as requested

Thank you

Hi Gustavo,

My situation is like this. I have two users, operator and supervisor. Both of them should write their transaction data to different database. I managed to implement this with your great multiactiverecord extension. However, the problem is with the inheritance. Operator write the data to ext_db defined in yii as db. While supervisor write the data to int_db defined in yii as db_int. I can only make it work if I use the same copy of Transaction model, but Transaction will return db as connectionId and TransactionInt will return db_int as connectionId.

What I want to do is using inheritance where TransactionInt is inheriting from Transaction, and I only override the connectionId method.

Doing like above is not working. When the db_int is shutdown, the TransactionInt will try to read/get the data from the db instead. What I want is showing error message.

How should I do?

Thank you in advance.

Daniel