Virendra Negi
2009-Jul-16 09:14 UTC
many-to-many relationships between model using different db
Hello to all I am finding out ways to set many-to-many relationships between my two models with each model belonging to a separate database. for e.g 1. I have a "User" Model belonging to "database_1" 2. I have a "Project" Model which belongs to "database_2" Apparently there is many-to-many relationship between these two models. Had the Models been belonging to same databases my job would have been much easier I would either use hbtm or has_many_through associations for it but with each models belonging to there respective databases.I kind of got stuck with it Any Suggestion Thank Anyway -- Posted via http://www.ruby-forum.com/.
Rails List
2009-Jul-16 09:25 UTC
Re: many-to-many relationships between model using different db
Are you able to access both the databases in your single application?. If so, what connection settings you have?. -- Posted via http://www.ruby-forum.com/.
Virendra Negi
2009-Jul-16 09:59 UTC
Re: many-to-many relationships between model using different db
Rails List wrote:> Are you able to access both the databases in your single application?. > If so, what connection settings you have?.Yes I have defined a second database in my database.yml like this development: adapter: mysql encoding: utf8 reconnect: false database: database_1 pool: 5 username: root password: root123 host: localhost database_2: adapter: mysql reconnect: true database: database_2 username: root password: root123 host: localhost and i establish my connection for my second database like this class Project < ActiveRecord::Base self.establish_connection :database_2 end -- Posted via http://www.ruby-forum.com/.