View Single Post
Old May 30th, 2006, 4:51 AM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
The reason for this is that Ruby on Rails can only find the relationship between two tables automatically if you adhere to certain conventions.

By default, Rails will look for a primary key called "id", and foreign key table connectors called "<tablename>_id". Your database does not adhere to these defaults, therefore Rails cannot automatically find the right connections. Here's some information on these "magic" field names.

To fix your problem, you need to either modify the database to adhere to the defaults, or explicitly tell Rails the names of the key columns (see here). For instance:

truck.rb:
class Truck < ActiveRecord::Base
	set_primary_key 'OilID'
	has_many :oils, :foreign_key => 'vehicleID'
end
oil.rb:
class Oil < ActiveRecord::Base
	set_primary_key 'vehicleID'
	belongs_to :truck, :foreign_key => 'vehicleID'
end
Arevos is offline   Reply With Quote