views:

29

answers:

1

For example, posts table is in db1, categories table and category_post_join table are in db2. How to declare a many-to-many relationship between Post model and Category model?

'categories'=>array(self::MANY MANY, 'Category', 'category_post_join (post_id, category_id)')

works only if all tables are in the same database.

A: 

I don't think that's possible. The CActiveRecord functionality is based on a physical PDO connection, which is linked to a specific database. There is no support for doing a join across multiple database that I know of. I actually ran into the same problem a while ago and had to work around it.

I really hope there is a possible answer here, but I haven't found one so far.

Blizz
I prefixed the join-table name with database name (e.g., db2.category_post_join). It works for some cases.
powerboy
Yeah I guess that could work if the permissions and so on are correct. Given what Yii does with the queries and so on, I just didn't really feel comfortable doing that. Thanks for the feedback.
Blizz