Yii Framework Forum: MultiActiveRecord - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

MultiActiveRecord Using multiple databases connections in gii and model Rate Topic: ***** 2 Votes

#1 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 22 November 2010 - 10:04 PM

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
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
1

#2 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 23 January 2011 - 05:03 AM

Complete change in the code, check the extension link for more details
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#3 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 23 January 2011 - 07:19 AM

Moved to "Extensions" as requested
Find more about me.... btw. Do you know your WAN IP?
0

#4 User is offline   Gustavo 

  • Master Member
  • Yii
  • Group: Moderators
  • Posts: 916
  • Joined: 27-July 10
  • Location:Curitiba - Brasil

Posted 23 January 2011 - 07:38 AM

Thank you
--
Extensions:
translate modue - module to handle translations
multiActiveRecord - db selection in models
redisCache - redis cache component
mpCpanel - interact with cpanel api
mUploadify - use uploadify uploader in your application

Gustavo Salomé Silva
0

#5 User is offline   Daniel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 227
  • Joined: 26-September 09

Posted 14 November 2013 - 09:41 PM

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users