How can I do “rake db:migrate” with mongoid and active record?

不羁岁月 提交于 2019-12-08 09:50:20

问题


I want to migrate active record (mysql) database.

I use database both mongoid and active record. I typed this code.

rails generate active_record:migration CreateUsersTable

It worked. But I can't migrate it with active_record. How can I migrate active record like rake active_record:db:migrate?


回答1:


I found my problem. I missed adding active_record/railtie to application.rb

After I added following line, it works!

require "active_record/railtie"




回答2:


I experimented with mixing both AR and Mongoid in the same project. What works best is to create a new rails app with default AR settings and then add Mongoid gem. I had issues with initializers so I had to manually created some models.

class Armodel < ActiveRecord::Base
  ...
end

class Mngmodel
  include Mongoid::Document
  ...
end

I was able to create relationships bwn 2 different AR models and 2 different Mongoid models but not between AR model and Mongo model. I could see this being an interesting solution in certain cases and would be curious to hear of people who actually applied it in production.



来源:https://stackoverflow.com/questions/35077815/how-can-i-do-rake-dbmigrate-with-mongoid-and-active-record

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