Mongoid和ActiveRecord生成器 [英] Mongoid and ActiveRecord generators

查看:92
本文介绍了Mongoid和ActiveRecord生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Rails 3.1应用程序中同时具有ActiveRecord(MySQL)和Mongoid.一切都很好,除了所有生成器都使用mongoid生成模型.这样,当我:

I have both ActiveRecord (MySQL) and Mongoid in my Rails 3.1 application. Everything is fine, excepts all generators uses mongoid to generate models. This way, when i:

rails g model user

我收到类似mongoid的模型,但是我需要ActiveRecord结构和迁移.

i receive mongoid-like model, but i need ActiveRecord structure and migrations.

如何切换回AR?

推荐答案

Mongoid会覆盖模型生成器,但您可以将其切换回去.

Mongoid overrides the model generator, but you can switch it back.

在config/application.rb中,如果已经有一个类似于以下内容的块,则可以添加一行:

In config/application.rb you can either add a line if you've already got a block similar to this:

config.generators do |g|
  g.template_engine :haml
  ...
  g.orm :active_record
end

或者只是将整个配置行直接添加到文件中

Or just simply add the entire config line directly to the file

config.generators.orm :active_record

如果您想关闭迁移,也可以传递:migrations => false

You can also pass :migrations => false if you want to turn off migrations

这篇关于Mongoid和ActiveRecord生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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