I would do:

Passengers belong_to Car
Car has_many Passengers
Car has_one Driver, :class => Passenger

Dieter Lunn
http://www.coder2000.ca



On Mon, May 10, 2010 at 7:46 AM, John Sikorski <[email protected]> wrote:
> Let's say I have a car table that has many passengers so obviously the
> passenger table will have a foreign key to car.  The Car model has_many
> Passengers.  A car can have one and only one driver.  What's the best
> way to model this relationship?
>
> Hand coded get and set driver methods in the car class with one of the
> following keys.
> 1) a flag in the passenger table noting the passenger as driver
> 2) a passenger foreign key in car to note driver
>
>
> Extend passenger to make a Driver model and do either:
>
> 3) Car belongs_to Driver
>
> 4) Car has_one Driver
>
>
> Or something else?
>
> Thanks!
> --
> 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 this group at 
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>

-- 
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 this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to