Manivannan Jeganathan
2011-Nov-01 14:56 UTC
Rails 3 Multiple database with Joins conditions throws exception
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Maybe Matching Threads
- Problem with running "WEbrick"
- Puppetmaster with stored configs leaks file descriptors on CentOS 5
- mysql installation in Windows 7
- /usr/bin/ld: cannot find -lmysqlclient_r installing ruby gem mysql2.... in Fedora Linux + MySQL 5.5.15...
- Selecting one row or multiple rows per ID