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'不存在'。 –