Topic: Joining a table twice
I followed the tutorial here (http://jrhicks.net/96) to do a many to many relationship between two tables and it worked great. Now I'm attempting to take it one step further and have two many to many relationships with the same two tables.
I have a Game session table with a has and belongs to many relationship with a users table. That's working fine thanks to the tutorial, but I don't just want to know who played in that board game session, I want to record who won. And some games allow more than one person to win, so I can't just have a gsessions.winner field. I want to join up with the users table for a second time to record the winner ids. I'm already using gsessions_users as a lookup table for the first half of this, so I don't know what to do now. I created a table "winners" with columns gsession_id and user_id, but now I'm at a loss. A user has to be a player if they're going to be a winner, so I could add a column winner (boolean) to my lookup table instead of adding a second look up table.
If I were writing these queries by hand I think I would use a table alias to access the user table twice, but I'm not sure how to do that in RoR. I've read about has_many :through, but I don't know if that's what I need. Any idea?