[英]Ruby on Rails: Creating a model with multiple data sources
Right now my Rails app is configured to use MySQL.现在我的 Rails 应用程序配置为使用 MySQL。 But suppose I want to create a new model and store it in Redis as well as MySQL.
但是假设我想创建一个新的 model 并将其存储在 Redis 以及 MySQL 中。 I know there is a way to have more than 1 data source in database.yml, but is there a way to map a model to multiple data sources?
我知道有一种方法可以在 database.yml 中拥有多个数据源,但是有没有办法将 map 和 model 连接到多个数据源? So when I create an instance of the model, the model gets inserted into both MySQL and redis?
因此,当我创建 model 的实例时,model 会同时插入 MySQL 和 Z86A1B907D364BF703E6E394?
You can just use callbacks, such as:您可以只使用回调,例如:
after_commit:saveToRedis, :on_create after_commit:saveToRedis, :on_create
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.