Relations between two databases

I have two databases, lets call them local and global. I have table1 in the local database, and a table2 in both global and local databases. In the table1 i have a column called dbType, that tells me if this row is linked to the ‘global’ or ‘local’ database table. This I can accomplish by adding a condition parameter. But the problem is that YII can’t find table2global, because it is in another database. I tried to write globalDatabase.table2 as the table/model name, but then It tries to include a file called globalDatabase.table2… Am I missing something?

public function relations()


 return array(

  'table2list' => array(self::HAS_ONE, 'table2', 'table1PK', 'condition'=>'dbType=:dbType', 'params'=>array(':dbType'=>'local'));



This relation works when table1 and table2 are in the same database.

Did you try setting your AR’s tableName() method to “DATABASE.TABLE” instead of “TABLE”?


Thanks, worked like a charm.