I've been out of the rails dev world for a little while and am a bit rusty when it comes to setting up relationships and joins between tables, so apologies if this is a very simple question.
- I have a
Teammodel which has anidcolumn. - I have a
Matchmodel which hashome_team_idandaway_team_idcolumns. - I'd like to be able to call
@team.matchesand have anyMatchwhere either thehome_team_idoraway_team_idequal the@team.idshow up.
I can achieve it with the following query, but it's far from ideal.
@matches = Match.where(home_team_id: @team.id) || Match.where(away_team_id: @team.id))
So what's the recommended way to set up my models and relationships to achieve the above behaviour?
Thanks in advance!