I am in the process of building a league management app.
I currently have seasons, leagues and teams that are all working fine. I
can create a new season, add the leagues that are playing in it and the
teams that play within each of the leagues.
What I now want to do is create fixtures for the teams. I have generated
a fixtures model and associated it with teams (has_many :teams) and
teams with fixtures (has_many :fixtures).
What I would like to be able to do when a user sets up the fixtures he
can just press a submit button that will generate all of the fixtures
between the teams (each team plays the other twice). I have been able,
using .permutations (get_team_combinations =
Team.names.permutation(2).to_a) to generate an array of fixtures but I
am stumped as
to how it would be possible to have each of these entries in the array
saved as a fixture in the database.
Anybody got any ideas how this is possible or an alternative way of
generating the fixtures?
What I would like to be able to do when a user sets up the fixtures he
can just press a submit button that will generate all of the fixtures
between the teams (each team plays the other twice). I have been able,
using .permutations (get_team_combinations =
Team.names.permutation(2).to_a) to generate an array of fixtures but I
am stumped as
to how it would be possible to have each of these entries in the array
saved as a fixture in the database.
well rather than permuting the names, i’d work with the teams
directly, i.e.
Team.all.permutation(2) do |team1, team2|
Fixture.create(…)
end
and then in that block create the fixture object for team1 versus team
2. Note that if you had teams a,b,c then you’ll get both a,b and b,a
as 2 different permutations. This might be what you want (e.g. if in a
season each pair meets twice, swapping who is the home team and who is
the away team), but if it isn’t then try using combination instead of
permutation
Fred
Anybody got any ideas how this is possible or an alternative way of
generating the fixtures?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.