I have the following “Registration” table :

A player can Join multiple Match (like in the picture, player #12 joined the match #59).
Now I would like to show all players who have registered to the same games as current_player.
So I though I had to :
- Catch all match_id where
player_id = current_player - Catch all the players in each match.
Is it the good way ? Or should I know something magic ? How can I do that ?
Thanks for your help.
UPDATE
I tried this :
@matchs_du_joueur = Registrations.where(:player_id => current_user.id)
@joueurs = Player.joins(:registrations).where(:registrations => { :match_id => @matchs_du_joueur.match_id })
And I have this error :
undefined method `match_id' for #<ActiveRecord::Relation:0x6d8a3b0>
However, I have defined all the has_many_and_belongs_to .
Don’t know how to do.
Yep, that’s it. I’m assuming
then you can just use the following to get all the players that the current_player has matches with