I have used two different databases for my rails application: MongoDB
and MsSQL
using mongoid
and activerecord-sqlserver-adapter
adaptor respectively. Everything is well but there is a problem while generate Model. The problem is "how can I generate the model that relats to MongoDB or MsSQL differently?"
For example: I want to generate People
model relates to MongoID
and Animal
model with MsSQL
. While I generate with command: rails g model Animal name:string
it generates the model related to mongoid. How can I generate the model Animal with ActiveRecord that means related to MsSQL.
Please help me.
Thanks
Take the 2-minute tour
×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
|
|||
|
Based on Using Active Record generators after Mongoid installation? I believe this should work:
|
|||||||||
|
First let me just check that I've understood your question correctly: You have 2 databases and a series of models/migrations, and you want a way to tell rails which database to use when running a migration and accessing the database using your model? If I'm in the right area then you need to add a method to your migration which overrides the default
Where within your models add the line
to the top of your model file and the model will now know which DB to connect to. |
||||
|