Nicholas Bayley

Joined

6,610 Experience
59 Lessons Completed
1 Question Solved

Activity

You are correct.

Your Bet model would have two belongs_to associations (one for the creator and one for the backer or however you'd like to call them):

class Bet < ApplicationRecord
  belongs_to :creator, class_name: 'User'
  belongs_to :backer, class_name: 'User'
end

Your bets table would need two columns for the user's id. With the above snippet, you would need a creator_id and a backer_id column.

And then if you wanted to access the bets from a user (created and backed bets for example) you would create two has_many associations on the User model:

class User < ApplicationRecord
  has_many :created_bets, foreign_key: 'creator_id', class_name: 'Bet'
  has_many :backed_bets, foreign_key: 'backer_id', class_name: 'Bet'
end

Hope that makes sense.