My environment: Ruby 1.9.2p290, Rails 3.0.9 and RubyGem 1.8.8

unfortunately I have an issue when come across multiple database.

The situation is this: I have two model connect with two different
database and also establishing association between each other.
database connection specifying in each model, look likes

class Visit < ActiveRecord::Base
self.establish_connection "lab"
belongs_to :patient
end

class Patient < ActiveRecord::Base
self.establish_connection "main"
has_many :visits
end

I got an error when meet following scenario
@visits = Visit.joins(:patient)

Errors: Mysql2::Error: Table 'lab.patients' doesn't exist: SELECT
`visits`.* FROM `visits` INNER JOIN `patients` ON `patients`.`id` IS
NULL

Here 'patients' table is in 'main' database and 'visits' table in 'lab'
database
I doubt when executing the code, that Rails is considering 'patients'
table is part of 'lab' database [which holds 'visits' table].

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to