I can't figure this out...
this is the strangest error...
There is a Game with a Home and Away Team. The game table has hometeam_id and awayteam_id as foreign keys to the team table's id.
and in the view
class Game < ActiveRecord::Base
has_one :hometeam, :class_name => 'Team', :foreign_key => 'hometeam_id'
has_one :awayteam, :class_name => 'Team', :foreign_key => 'awayteam_id'
And this gets me:
<%= game.awayteam.class %>
Why is it looking for awayteam_id in teams and not in games? Am I using has_one incorrectly?
#42S22Unknown column 'teams.awayteam_id' in 'where clause': SELECT * FROM teams ... etc
Use belongs_to. Has_one looks in the foreign table, just like has_many.
And you'll probably want a has_many :games on the Team side, too.
Remember this...if you have has_one/many on one side of the association, you'll usually want a belongs_to on the other side.