[u]in single database I use for relations this code :
For Example [/u][/color]
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
'section' => array(self::BELONGS_TO, 'Sections', 'section_id'),
'editby0' => array(self::BELONGS_TO, 'Users', 'editby'),
'topstories' => array(self::HAS_MANY, 'Topstory', 'article_id'),
);
}
I
[b]
So if table ([color="#FF0000"]y[/color]) in database [[color="#FF8C00"]B[/color]] have relation with table ([color="#FF0000"]x[/color]) in database [[color="#FF8C00"]A[/color]] .
I suspect that the relations will work as long as they are lazily loaded. This is assuming that the two active record classes have been assigned different connections. I’m not sure what will happen if you attempt to load eagerly, but it’s worth trying to see what happens.
You may be able to avoid this problem completely, by just using one connection and changing the tableName() method in each model class to include the database name:
public function tableName()
{
return 'database.table';
}
I don’t know if this will work, but it might be worth trying. If it does work, it’ll allow you to join eagerly as well as lazily. It also assumes that you’re happy to give access to both databases to a single account.