I want my Entry model to use multiple databases. When a customer joins the network a new database is automaticly created for this customer. Other models will use same database. Is this possible in rails?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Funny, I just came up with a solution to this ten minutes ago…
Here goes…
First off define the separate database connection in your database.yml
mine has
Then I added an additional one (for me, I’ve a legacy database I want to connect to…)
Repeat this for different environments where appropriate
The next thing I did was create a new file in ‘lib’ called ‘legacy_model.rb’ and it looks quite simply like this
Now, to make use of this, I just create a class/model and inherit from LegacyModel like so…
And voila, it’ll access the legacy database instead of the one I’m using.
There are probably better solutions, but this seems to work for me – hope it helps!