I've got two models from two different databases that I wish to
associate if possible. The association is not based on a primary key
for either model, but on a "job_number" field that both tables have
(which is unique in both tables). Here's what I tried:
class Job < ActiveRecord::Base
establish_connection(:adapter => "oracle", ...)
self.table_name = 'job'
self.primary_key = 'job_id'
has_one :schedule, :foreign_key => :job_number
class Schedule < ActiveRecord::Base
establish_connection(:adapter => "postgresql", ...)
belongs_to :job, :foreign_key => :job_number
j = Job.find_by_job_number('12345A')
j.schedule => nil # ???
# Also tried:
s = Schedule.find_by_job_number('12345A')
s.job => nil # ???
No error, but the association should definitely not be nil.
What's the proper way to do what I'm trying? On a side note, how can I
inspect the sql that AR is generating?