Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在我的 Rails 应用程序中,我想使用存在于多个数据库中的表。如果我定义一个模型,那么它只能映射到一个数据库。那么,我如何在其他数据库中使用同一张表。
我应该为每个我认为不会是 DRY 的数据库为同一个表创建单独的模型还是有更好的方法?
谢谢
用于establish_connection动态更改数据库
establish_connection
例如:
# database.yml db1: host: host1 database: db1 db2: host: host2 database: db2 Model.establish_connection :db2