0

I'm using rails 4.1.5 How to JOIN tables of two different databases in Ruby on Rails.

I have a Model(Users) in DB1 and another model(Assets) in DB2. Association between Users and Assets is: User has_many assets and Asset belongs_to User.

Query: I want to Join these two tables, right now I'm using raw sql query in my application. "SELECT * FROM DB1.users user JOIN DB2.assets asset ON asset.user_id = user.id"

Is there any better solution in RoR?

Rithesh B
  • 198
  • 1
  • 9
  • Are the databases in the same database engine on the same server? Does the database user have access to both databases? – spickermann Aug 09 '18 at 12:51
  • Yes, both the Databases are on the same server and user have access to both DB. – Rithesh B Aug 09 '18 at 12:56
  • 1
    Did you try the answers to [this question](https://stackoverflow.com/questions/7968221/rails-3-multiple-database-with-joins-condition)? – spickermann Aug 09 '18 at 13:04

0 Answers0