在 Rails 中结合 MongoDB 和 Postgresql?
是否可以将 AR 与 MongoMapper/MongoID 结合起来?
如果是这样,有这方面的教程/文档吗?
Is it possible to combine AR with MongoMapper/MongoID?
If so, are there tutorials/documentations for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是小菜一碟。您实际上不需要做任何特别的事情,只需相应地使用不同的适配器制作模型即可。这是一个示例 Mongoid 文档:
为了进行比较,这里是 activerecord:
只要确保不要混淆它们。例如,不要在继承自 ActiveRecord::Base 的类中包含 mongoid。我推荐 Rails 3,因为它可能会在本周发布,并且到目前为止 RC 已经非常稳定。
Yes, it is a piece of cake. There really isn't anything special you need to do, just make models with the different adapters accordingly. This is an example Mongoid document:
For comparison, here is activerecord:
Just make sure not to mix them up. For example, don't include mongoid on a class that inherits from ActiveRecord::Base. I recommend Rails 3, as it's probably going to release this week, and the RCs have been really solid so far.
是的,这是可能的。您能更具体地说明您想要实现的目标吗?如果您使用 Rails 3,那就更容易了,因为 mongoid 和 ActiveRecords 使用 ActiveModel 作为接口。
Yes it's possible. Can you please be more specific on what you want to achieve? It's even easier if you use Rails 3 because mongoid and ActiveRecords uses ActiveModel as the interface.