I have a table X connected to table Y through containing When I want to inner join (matching) this with table Z using hasOne and a function. CakePHP automatically connects to the nonexisting default row through hasOne
public function initialize(array $config)
{
$this->belongsTo('Y', [
'bindingKey' => 'initialen',
'foreignKey' => 'initialen'
]);
$this->hasOne('Z');
}
further
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;
}
I am getting error
Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Z.search_id' in 'on clause'