I have corresponding Active Records, and I’m struggling to create relations. I want to create relation ‘youthmatches’ on Team AR that would follow this pattern:
SELECT * team t LEFT OUTER JOIN match m on (t.youth_team_id=m.home_team_id or t.youth_team_id=m.away_team_id) and source_system='youth'
I cannot get this to work both lazy loading and relational way.
I don’t quite understand how your database is setup. Does your team table have a composite primary key with those 2 id fields? Shouldn’t the match team id columns be paired up with the team.team_id column?
Anyway from the team model, I think what you should be doing is creating 2 has_many relations. One to grab matches where that team is the "home" team, and another where they are the "away" team. If you want to grab all the matches for a specific team, then I think it would be better to start from match model