Foreign Key Confusion

I'm confused on ActiveRecord, particularly where integration to legacy DBs are concerned. I am hoping someone can point me to a reference that explains foreign_key and association_foreign_key for me.

If I have a legacy MySQL DB with two tables specifid below, wherein I have a table, 'leads' which contains an index to 'origins' such that

CREATE TABLE `origins` (   `id` int(11) NOT NULL auto_increment,   `originname` varchar(60) NOT NULL default '' )

CREATE TABLE `leads` (   `id` int(11) NOT NULL auto_increment,   `howdidyouhear` int(11) NOT NULL default '0',   `amount` double NOT NULL default '0',   `homeplan` int(3) NOT NULL default '0' )

My problem is mapping this in active record. I am mapping it as follows (I am not certain this is correct, can someone please confirm? Does someone have a link that explains this better to me? Thanks, Ike) :

class Origin < ActiveRecord::Base   has_many :leads, :foreign_key => 'originname' end

class Lead < ActiveRecord::Base   belongs_to :origin, :foreign_key => 'howdidyouhear' end

This should work for you

class Origin < ActiveRecord::Base has_many :leads, :foreign_key => ‘‘howdidyouhear’’ end

class Lead < ActiveRecord::Base belongs_to :origin, :foreign_key => ‘howdidyouhear’


Regards, Jatinder