Open chf2 opened 9 years ago
I'm going to have to ask you more about implementing this the second way, but for now I at least added a table to the schema doc for matchups, because you're right... I definitely need that.
OK sure, let's take a few minutes tomorrow to go over it
I started trying to implement the schedule this way and I am having one problem in particular. I'm not sure how to get matchups without defining two associations (one though team_1_id and the other through team_2_id).
I think one possible solution is to define a custom association -- something like a model method on team #matchups that returns Team.where(id: Schedule.where("team_id_1 = ? OR team_id_2 = ?", id, id) (maybe break that up). Does that make sense / would it solve the issue?
You can also define "home_games" and "away_games" associations and then just make a method that combines the two results
I tried the second way and I am having some trouble getting the League's has_many :matchups to work. It seems like because I am getting an array back instead of an association.
I think you have a couple options for wins / losses. On the one hand, you could increment wins and losses on the teams after the results of a week are in. If you do this, I'd set a default at zero for clarity.
A potentially better solution would be to have a schedule table, with team_1_id, team_2_id, week, and winning_team_id (for starters), and calculate wins and losses based on analysis of the join table. This also adds in a schedule which feels kind of core to the functionality.