Multiple Adapters Use case : Mysql , Mongodb & Multiple Mongodb in one project - leebalaji1234/bgjob GitHub Wiki

Multiple databases in active record bases and mongo odm bases

Reference : http://stackoverflow.com/questions/11230473/multiple-rails-orm

Code 1

A typical Active record class

class Account < ActiveRecord::Base ... end

A new database connection

class NewConnection < ActiveRecord::Base self.abstract_class = true establish_connection "users_database" end

A new Active record class using the new connection

class User < NewConnection ... end

Mixing ORMS is easy. for example mongodb (with mongoid), simply dont inherit from active record and include the following in the model you want to use mongo:

class Vehicle include Mongoid::Document

field :type field :name

has_many :drivers belongs_to :account

end

Using Active Record generators after Mongoid installation?

m using MongoDB via Mongoid integration, as well as ActiveRecord in a project. I would like to generate migrations for active record, and Mongoid is the default when I run.

rails g migration

Any ideas how to specify AR as my default generator for migrations, models, etc?

Answer

rails g active_record:migration example :

balaji:~/voicepoc/bgjob$ rails g active_record:migration scaffold OptinService phone:string status:integer create db/migrate/20150422100925_scaffold.rb

Connecting two databases mongoid

http://stackoverflow.com/questions/16400458/connecting-to-two-databases-mongoid

hmm well can you do this seem like you messed your yaml file

development: sessions: default: database: db_development username: my_username password: my_password hosts: - myserverip:27017 options: consistency: :eventual writeable: database: db2_development username: myusername2 password mypassword2 hosts: - myserverip2:27018 options: consistency: strong

In your model just write this

store_in session: "writeable"

class MyModel include Mongoid::Document store_in session: "writeable" field :name, type: String field :age, type: Integer end

FYI Never tested with password options but i guess it would work

Hope this help