views:

20

answers:

1

Hi, I have 2 entities:

Table/Entity 1: RetrievedDataRecords

Columns:

id

record_key

Table/Entity 2: SourceKeys

Columns:

id

key_name (unique key)

I cant alter these tables for legacy reasons, but want rails relationship between RetrievedDataRecord and SourceKey using record_key and key_name (they are the same key)

in RetrievedDataRecord, I tried something like:

belongs_to :source_key, :foreign_key => :record_key

but this doesn't work. I need some way to tell rails that record_key on this table is the same as key_name on the other table....

A: 

You have to specify also the primary_key:

belongs_to :source_key, :primary_key => :key_name, :foreign_key => :record_key

It should work!

jpemberthy
awesome, thanks!
Joelio