Ok, the associations are getting the better of me again. My models for 
Business, VehicleType and Vehicle.


class Business < ActiveRecord::Base
  has_many :vehicles
end

class VehicleType < ActiveRecord::Base
  has_many :vehicles
end


class Vehicle < ActiveRecord::Base
  belongs_to :business
  belongs_to :vehicle_type
end

Now, my problem is in creating a new vehicle. I can create a Business 
and VehicleType just fine, but when I try to create a Vehicle I run into 
problems with the foreign keys.

If I try:
first_vehicle = Vehicle.new(:veh_name => "test")
#then I try adding the new vehicle to my existing business
business.vehicles << first_vehicle

it generates an error that the foreign key for the vehicle_types table 
cannot be null. If I try to append the vehicle to the VehicleType first 
I get an error that the business_id cannot be null.

Any ideas here?

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to