Используйте оператор соединения
Я не знаю, какую версию cakephp вы используете, но я использую cakephp 2.0.
$this->Model->find('all',[
'joins' => [
[
'table' => 'Manufacturers',
'alias' => 'Manufacturers',
'type' => 'LEFT',
'conditions' => [
'Category.Cat_ID = Manufacturers.Cat_ID'
]
],
[
'table' => 'Model',
'type' => 'LEFT',
'conditions' => [
'Model.CAR_ID = Manufacturers.CAR_ID'
]
]
]
]);
, если вы хотите ограничить какую категорию вы будете использоватьзатем используйте условия как ниже
$this->Model->find('all',[
'joins' => [
[
'table' => 'Manufacturers',
'alias' => 'Manufacturers',
'type' => 'LEFT',
'conditions' => [
'Category.Cat_ID = Manufacturers.Cat_ID'
]
],
[
'table' => 'Model',
'type' => 'LEFT',
'conditions' => [
'Model.CAR_ID = Manufacturers.CAR_ID'
]
]
],
'conditions' => [
'Category.Cat_ID' => 1
]
]);
Примечание: использование '[]' и array () технически одинаковы, но, тем не менее, вот пример кода с использованием array ().
$this->Category->find('all',
array(
'joins' => array(
array(
'table' => 'Manufacturers',
'alias' => 'Manufacturers',
'type' => 'LEFT',
'conditions' => array(
'Category.Cat_ID = Manufacturers.Cat_ID'
)
),
array(
'table' => 'Model',
'type' => 'LEFT',
'conditions' => array(
'Model.CAR_ID = Manufacturers.CAR_ID'
)
),
),
'conditions' => array(
'Category.Cat_ID' => 1
)
));
Обновление 2
$this->Model->find('all',
array(
'joins' => array(
array(
'table' => 'Manufacturers',
'alias' => 'Manufacturers',
'type' => 'LEFT',
'conditions' => array(
'Model.Car_ID = Manufacturers.Car_ID '
)
),
array(
'table' => 'Category',
'type' => 'LEFT',
'conditions' => array(
'Category.Cat_ID= Manufacturers.Cat_ID'
)
),
),
'conditions' => array(
'Category.Cat_ID'=>$cat_id
)
));