From: Jason Foreman Date: 2005-06-07T22:24:02+09:00 Subject: Re: Rails/ActiveRecord Nuby question. On 6/6/05, Harold Hausman wrote: > .. > class Match < ActiveRecord::Base > has_one :team_one, :class_name => "Team", :conditions => 'id = #{one}' > has_one :team_two, :class_name => "Team", :conditions => 'id = #{two}' > end > > *note: 'one' and 'two' are the names of the columns in the matches > table where I store the team ids that participated in the match. > > What I was hoping was that each Match object would then have two new > child objects called team_one and team_two which would be Team > objects. This did not work, near as I can tell it formulated some sql > string which contained some match_id gibberish in the where clause and You want to have: class Match < ActiveRecord::Base belongs_to :team_one, ... belongs_to :team_two, ... end belongs_to signifies that the foreign key column is in THIS table, ie the table of the same model. has_one signifies that the foreign key column is in the table of the related model. Very common mistake. But I believe there is significant documentation to explain why the relations are named as they are though. Hope that helps. BTW, there is a mailing list specifically for Ruby On Rails [1], which would be more appropriate for these questions than ruby-talk. Jason [1] http://lists.rubyonrails.org/mailman/listinfo/rails