Forum: Ruby on Rails has_one mapping with arbitrary right and left hand side keys

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jon G. (Guest)
on 2005-12-19 19:23
I have two tables:

table_1:
tab1_id,
other_id

table_2:
id,
tab2_id,
something_else

I would like to specify a has_one mapping from table_1 to table_2 but
specifying that the join is based on (table_2.tab2_id =
table_1.other_id).

I am half way there with:

class Table1 < ActiveRecord::Base
	set_table_name "table_1"
	set_primary_key "tab1_id"
	has_one :Table2, :class_name => "Table2", :foreign_key => "tab2_id"
end

However, as you can see, this will join on table_2.tab2_id =
table1_1.tab1_id and not on table_1.other_id.

Is there a notation that I am missing to express this, or is there
another way of acheiving this. I cannot alter the DB schema.

Thanks in anticipation.
This topic is locked and can not be replied to.