So I have an Athlete model, which has_many Games, and each game has_many Stats. Each Stat has a sport_id, and I need to join all of the games (for a specific athlete) which have stats whose sport_id is a certain id.
Here is a visual of the database model hierarchy:
Athlete
-> has_many :games
-> has_many :stats
-> sport_id
I need all the games which have a certain sport_id (determined by checking the sport_id of at least one of that game's stats), and the sport_id could be passed to the scope.
Any help? New to writing scopes, but I'm certain this can be done.
EDIT: I'm aware that sport_id should've been an association inside of the Game model, but I didn't build the initial product, I simply need to get this scope to work as I mentioned.