php - Why am I getting a “Not Associated” error even though the HABTM association is in place? -
i'm making tournament scoring software bike polo league. goal match teams in such way gets chance play every other team before repeat matches start.
in match entity class, have function called creatematches should find teams , associated matches. there habtm relationship between matches , teams, join table. relationship works fine - i've selected teams (contain matches) , matches (contain teams) in several controller methods, saved associations through forms, , on. so, in entity function, error "teams not associated matches. caused using auto-tables? ...." , on. can tell me what's wrong?
here's 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; }
here's init function match.php:
public function initialize(array $config) { parent::initialize($config); $this->table('matches'); $this->displayfield('id'); $this->primarykey('id'); $this->addbehavior('timestamp'); $this->belongsto('rounds', [ 'foreignkey' => 'round_id', 'jointype' => 'inner', 'classname' => 'swissrounds.rounds' ]); $this->belongstomany('teams', [ 'foreignkey' => 'match_id', 'targetforeignkey' => 'team_id', 'jointable' => 'matches_teams', 'classname' => 'swissrounds.teams' ]); }
here's init function team.php:
public function initialize(array $config) { parent::initialize($config); $this->table('teams'); $this->displayfield('name'); $this->primarykey('id'); $this->hasmany('players', [ 'foreignkey' => 'team_id', 'classname' => 'swissrounds.players' ]); $this->belongstomany('matches', [ 'foreignkey' => 'team_id', 'targetforeignkey' => 'match_id', 'jointable' => 'matches_teams', 'classname' => 'swissrounds.matches' ]); }
i don't believe i've touched either of functions - both generated cake bake.
error message quite exact, not descriptive. says teams not associated matches.
well, tested minimal setup, difference, did not have tables inside plugins. , no errors detected. so, pretty sure cakephp cant find table classes inside swissrounds
-plugin reason.
Comments
Post a Comment