Rails 3:如何同时使用活动记录和Mongoid [英] Rails 3: how to use active record and mongoid at the same time

查看:62
本文介绍了Rails 3:如何同时使用活动记录和Mongoid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了很多,人们建议将nosql与sql数据存储一起使用.例如,在mysql中有一些报告审计跟踪或日志信息,在mongodb中有一些线程化的分层数据.

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.

是否可以在mysql以及mongoid上挂起具有活动记录的rails?

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?

推荐答案

要做到这一点,应该保持Rails完整,因此不要像Mongoid文档中通常建议的那样排除库.您需要分别配置它们,因此需要有一个database.yml和mongo.yml配置文件,并且需要确保它们都已加载.

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.

此后,您可以按模型启用/禁用AR和Mongoid.

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

这篇关于Rails 3:如何同时使用活动记录和Mongoid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆