So I want to implement many to many relation between these two models:
class Bet < ActiveRecord::Base
belongs_to :betting_event
has_and_belongs_to_many :gambler_bets
validates_presence_of :odd, :outcome, :description, :betting_event_id
end
And
class GamblerBet < ActiveRecord::Base
belongs_to :gambler
has_and_belongs_to_many :bets
end
I wrote and ran a migration :
class CreateBetsGamblerBets < ActiveRecord::Migration
def change
create_table :bets_gambler_bets, :id => false do |t|
t.belongs_to :bet
t.belongs_to :gambler_bet
end
end
end
So the question is: where and how to write a method that would add bets to a Gambler
and store every one of them with bet_id
and gambler_bet_id
in bets_gambler_bet
table ?