I’m making some tournament scoring software for my bike polo league. The goal is to match up teams in such a way that everyone gets a chance to play every other team before repeat matches start.
In my Match Entity class, I have a function called createMatches that should find all teams and associated matches. There is a HABTM relationship between matches and teams, with a join table. This relationship works fine - I’ve selected teams (contain matches) and matches (contain teams) in several controller methods, saved associations through forms, and so on. But even so, in this Entity function, I get the error “Teams is not associated with Matches. Could this be caused by using Auto-Tables? …” and so on. Can anyone tell me what’s wrong?
Here’s the method in question.
public function createMatches($tournamentId) {
$team = TableRegistry::get('Teams', ['contain' => ['Matches']]);
$teams = $team->find('all', ['conditions' =>
['tournament_id' => $tournamentId],
'contain' =>
['Matches' =>
['fields' =>
['Matches.id']
]]]);
return $teams;
}