How can I do “rake db:migrate” with mongoid and ac

2019-06-14 08: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.