Hi,

I have an interesting dilemma, which is best shown through example.
Say I have Car and Part models which have a HABTM association.  In
this case though, the Part class is an STL with Wheel and
SteeringWheel as models.  Is there a way to setup the Car model with
both HABTM and has_one relationships to the same table?

class Part < ActiveRecord::Base
  has_and_belongs_to_many :cars
end
class Wheel < Part
end
class SteeringWheel < Part
  # do I put a new association here?
end

class Car < ActiveRecord::Base
  has_and_belongs_to_many :cars
  has_one :steering_wheel
end

This way, I could do something like so:

car = Car.new
car.wheels << Wheel.new( :brand => 'Dunlop')
car.wheels << Wheel.new( :brand => 'Dunlop')
car.wheels << Wheel.new( :brand => 'Bridgestone' )
car.wheels << Wheel.new( :brand => 'Bridgestone' )
car.steering_wheel = SteeringWheel.new( :brand => 'Sparco' )

-- 
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to