更新时间:2023-08-28 14:39:22
您没有正确设置关联
TeamsTable.php
$this->hasMany('MatchSchedulesA', [
'foreignKey' => 'team_a',
'className' => 'MatchSchedules'
]);
$this->hasMany('MatchSchedulesB', [
'foreignKey' => 'team_b',
'className' => 'MatchSchedules'
]);
在MatchSchedulesTable.php中
$this->belongsTo('TeamsA', [
'foreignKey' => 'team_a',
'joinType' => 'INNER',
'className' => 'Teams'
]);
$this->belongsTo('TeamsB', [
'foreignKey' => 'team_b',
'joinType' => 'INNER',
'className' => 'Teams'
]);
和
$matches = $this->MatchSchedules->find('all', [
'contain' => [
'TeamsA',
'TeamsB
]
]);
很高兴您重新命名:
MatchSchedulesA to HomeMatches
MatchSchedulesB to GuestMatches
team_a to home_team
team_b to guest_team
TeamsA to HomeTeams
TeamsB to GuestTeams