ruby on rails - database structure for league application -


First post I apologize if I am not following the right guidelines.

I am designing an online league management app in the rail and there are some problems in the database design, which I now know by moving forward with what I have achieved and it does not work later Has been doing.

At present I have the following models:

  class league & lt; ActiveRecord :: Base is has_many: teams are_Important: Player & Class Team & lt; ActiveRecord :: Base is_to: League is_maya: Player & Class Player & lt; ActiveRecord :: Base is_to: League related_to: End of Team   

The idea is that leagues can be made from teams of any team's players, or just individual players. I currently have a league_type feature in the league table which recognizes that league is for teams or players or not my first question is is this a good way to handle this situation?

It seems that this can be a problem, when I try to make a match, because it will be made of either players or teams, I originally thought that I had home_id and away_id There is a matching model with the attributes, and then on the basis of the league type, the player populates them with either _ids or Team_ID, but it does not look like a good design for me. Is considered to quote, perhaps it is the best way? E.g.

  Class matches & lt; ActiveRecord :: Base is_to: home_matchable, polymoprhic: true is_to: away_matchable, polymoprhic: true end   

and then "has_many: home_matches, as: home_matchable" and "has_many: away_matches, such as: For telecom and player

I am currently meeting with limited views and controllers, I think the league is for teams or players or not, there is a need to check regularly, so much All "if league_type == 'teams do something else in my code' statements which are a bit ugly Specifically, if I want to fix the track down, then I would like to add a "couple" type for example, so they will turn into 'if' teams and then 'player' and then 'etc.' .

Sorry I hope that for a long time, any help is greatly appreciated!

Why does not a player force to join a team by default? When making a player in DB, you will make a team for yourself and make him the sole member.

You can also mark these teams with a boolean who is telling you that these are not multi-player teams.

In this way, you will only deal with teams while making matches. I personally do not like the polymorphic approach, it may be difficult to manipulate different models while reaching your organizations.

Comments