rails relationship using unique key -


table/entity 1: retrieveddatarecords

columns:

id

record_key

table/entity 2: sourcekeys

columns:

id

key_name (unique key)

i cant alter these tables legacy reasons, want rails relationship between retrieveddatarecord , sourcekey using record_key , key_name (they same key)

in retrieveddatarecord, tried like:

belongs_to :source_key, :foreign_key => :record_key

but doesn't work. need way tell rails record_key on table same key_name on other table....

you have specify primary_key:

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

it should work!


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -