From: Mike Harris Date: 2006-11-01T23:59:22+09:00 Subject: Re: Syntax q on ActiveRecord Ike wrote: >"Mike Harris" wrote in message >news:4547AC2E.9020102@prodigy.net... > > >>Ike wrote: >> >> > > > >>Using the column names primary_associate_id and secondary_associate_id, >>instead of associatekey1 and associatekey2 >> >>class Customer < ActiveRecord::Base >> belongs_to :primary_associate, :class_name => 'Associate', :foreign_key >>=> 'primary_associate_id' >> belongs_to :secondary_associate, :class_name => 'Associate', :foreign_key >>=> 'secondary_associate_id' >>end >> >>Rails automatically infers the class_name and foreign_key from the name of >>your association. You can always just name your association whatever you >>want and specify those things explicitly, like I do here. >> >> > >Thanks Mike, > >I'm stuck with legacy DB column names here however -- I think maybe I need >to look deeper into the ActiveRecord source. Thanks for your help. -Ike > > > > > > I just changed the names of the columns in my example cause I felt like it. This is perfectly fine as well class Customer < ActiveRecord::Base belongs_to :primary_associate, :class_name => 'Associate', :foreign_key => 'associatekey1' belongs_to :secondary_associate, :class_name => 'Associate', :foreign_key => 'associatekey2' end The :foreign_key option tells it the name of the column you are using. Have you looked at the manual that was linked earlier in the thread? http://api.rubyonrails.com/ Here's the specific page for this http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000532 The documentation isn't great, but for most problems at this level it tells you what you need to know.