Rails 3: how to use active record and mongoid at the same time

[亡魂溺海] 提交于 2019-12-17 22:44:07

问题


I read alot that folks recommend using nosql together with sql datastores. For example have some reporting audit-trailing or log information in mysql and some threaded hierarchical data in mongodb.

Is it possible to hook up rails with active record on mysql as well as mongoid?

Out of the box it seems not to work...Any hints? Or is this a not recommended approach?


回答1:


Well, to do it, you're supposed to leave Rails intact, so don't exclude libraries like it's commonly suggested in Mongoid documentation. You need to configure them separately, so you need to have a database.yml and mongo.yml config files and you need to make sure they're both getting loaded.

After that, you can enable/disable AR and Mongoid on a per-model basis.

class User < ActiveRecord::Base
  #this is an AR model
end

class Item
  include Mongoid::Document
  #this is a Mongoid model
end


来源:https://stackoverflow.com/questions/5411283/rails-3-how-to-use-active-record-and-mongoid-at-the-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!