我有一個表X連接到表Y通過包含 當我想內聯接(匹配)這個表與Z使用hasOne和函數。 CakePHP的自動通過hasOneCakePHP 3.x hasOne插入默認外鍵
public function initialize(array $config)
{
$this->belongsTo('Y', [
'bindingKey' => 'initialen',
'foreignKey' => 'initialen'
]);
$this->hasOne('Z');
}
進一步連接到不存在的默認行
public function search($c)
{
$query = $this->find('all')->contain('Y')->matching('Z', function ($q) use ($c) {
return $q->where(['Z.client_ID' => $c]);
});
return $query;
}
我收到錯誤
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Z.search_id' in 'on clause'
正確的,但比這將增加也給查詢。我不想要的。 比方說,我指定的外鍵爲 'TEAM_ID' FROM ''archief' searches' INNER JOIN''archief_Z' ON Z'( 'Z'.'client_ID' = 81 和'searches'.'ID '=('Z'.team_ID') ) LEFT JOIN'archief_Y'' Y' ON'Y'.initialen' =('searching'.'initialen') – Joost