Ruby on Rails Tuesday, November 1, 2011

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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment