views:

64

answers:

1

I am trying to model a very simple system, but the Rails way of doing this is escaping me. I'd like to have two entities, a User and a Bet. A bet has two users and a user has many bets. I'd like the creating User of the bet to be able to mark it as resolved (do any form of update/delete on it).

My initial thinking was to have a User act two ways, as a better or a responder. many_to_many associations in rails may be the right option, with an extra column on the bet table to note who owns the model. But, then you are repeating one of the User's id's twice.

Thanks in advance!

+1  A: 

I think this is what you want:

class User
   has_many( :bets, :foreign_key => 'bettor_id', :class_name => 'Bet' )
   has_many( :responses, :foreign_key => 'responder_id', :class_name => 'Bet' )
end

class Bet
   belongs_to( :bettor, :class_name => 'User' )
   belongs_to( :responder, :class_name => 'User' )
end
Farrel