简体   繁体   中英

How to declare many-to-many relationships if the join table is in a different database?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM