Hi, I’ve two database tables 1-N related and one of them doesn’t have id
column:
matches (id, more columns), match_details(match_id, … more columns)
Also have two models that represents these tables:
Match MatchDetail
has_one :match_detail belongs_to :match,
:foreign_key => ‘match_id’
When I create a Match object with a new MatchDetail object related to
it,
everything works fine, but when I try to update some MatchDetail
attributes
I get an update error from DB:
@match = Match.new
@match.match_detail = MatchDetail.new
@match.save
OK!!!
@match = Match.find(params[:id])
@match.play <-------- THIS METHOD MODIFIY SOME VALUES OF match_detail
@match.save
Mysql::Error: Unknown column ‘id’ in ‘where clause’: UPDATE
match_details SET
home_goals
= 2, match_id
= 1, away_goals
= 0 WHERE id = NULL
id doesn’t exist because the migration for this table specified not id
column:
create_table :match_details, :id => false do |t|
t.column :match_id, :integer, :null => false
t.column :home_goals, :integer, :default => 0
t.column :away_goals, :integer, :default => 0
end
I also have try to declare match_id column as primary key, but doesn’t
work,
it raises the same error.
What I forgot to do?