1
我有一個表match_schedules
,它存儲兩個teams
之間的匹配項。有teams
表存儲團隊信息。的match_schedules
在cakephp 3中鏈接相同的表與兩個外鍵3
列是
+-----+---------+---------+-------+-------+
| id | team_a | team_b | date | venue |
+-----+---------+---------+-------+-------+
因爲我有兩列team_a
和team_b
引用teams
表,我不能使用team_id
在兩列外鍵。
現在,我想這兩列與teams
表,這樣我可以輕鬆檢索喜歡
$matches = $this->MatchSchedules->find('all', [
'contain' => [
'Teams'
]
]);
相關數據我已經嘗試了這個 在TeamsTable.php
$this->belongsTo('MatchSchedules', [
'foreignKey' => 'team_a',
'joinType' => 'INNER'
]);
$this->belongsTo('MatchSchedules', [
'foreignKey' => 'team_b',
'joinType' => 'INNER'
]);
關聯In MatchSchedulesTable.php
$this->hasMany('Teams', [
'foreignKey' => 'team_a'
]);
$this->hasMany('Teams', [
'foreignKey' => 'team_b'
]);
但這不起作用。
改變 'MatchSchedules' 到 'MatchSchedulesA' 和 'MatchSchedulesB', '團隊' 到「TeamsA'and 'TeamsB' – Salines
這給'MatchSchedules沒有關聯在'$ matches = $ this-> MatchSchedules-> find('all',['contain'=>'Teams']);' –
this'given'Base table or view not found:1146''team_a'不存在'。 –