Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7865865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:12:51+00:00 2026-06-03T00:12:51+00:00

I have been working with rails for almost a year now and I have

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:12:52+00:00Added an answer on June 3, 2026 at 12:12 am

    Maybe this will help you clear up some many-to-many questions you have:

    Many-to-Many

    With your routes, you may not have to nest your routes so deeply… separating may be a better approach.(up to you on how you want your routing)

    I see a few many-to-many relationships forming. A player can play many sports, and a perticular sport could have many players. A season can have many different sports, and a sport can have multpile seasons through the years.

    Once you have your models figured out, if you want a form that manipulates two different models, you should look into nested_forms

    Nested_forms

    Hopefully this will help you get started/clear some things up for you!

    I too built a sports app(basketball), and ran into some issues with many-to-many relationships and nesting forms here. Maybe you can use this as reference/guide along the way

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working with Ruby on Rails for over a year now and
I have been working with Rails for a little while now. I got some
I have been working on Ruby on rails project for a while now, when
Okay I have been working on this for about 2 hours and am sure
I have been working on this, very, small photo cms lately. And now i
I have been working on this for a while. Tried many many different things,
I have been working with my rails application and since today I have not
I'm trying to get emberjs working on rails and have been following this tutorial:
Have been working on this question for a couple hours and have come close
I have been working on this app for at least 3-4 months and just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.