I have been working with rails for almost a year now and I have been in situations where I am not sure when to use the many-to-many association. This is my current situation.
I have a player, season, and sport.
player.rb
has_many :seasons, :dependent => :destroy
season.rb
belongs_to :player
has_many :sports, :dependent => :destroy
sport.rb
belongs_to :season
A player has_many :seasons and season belongs to player. Then I have sport which belongs to season and seasons has_many :sports.
What I would like is for a player to add a new season(ex. 2011-2012, 2012-2013, 2014-2015 etc) then after the season is created I would like for the player to add the sports they are currently playing that season. I am very confuse at this point because the way I am doing it now forces me to use nested resources that are 3 level deep like so
routes.rb
resources players do
resources :seasons do
resources :sports
end
end
If I were to use 3 level deep nested resources I would have to add players to my form that only accepts 2 options.
_form.html.erb
<%= form_for([@season, @sport]) do |f| %>
Would i use a many-to-many association for this or how should I approach this?