Has_one mapping with arbitrary right and left hand side keys


#1

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.