У меня есть несколько вложенных моделей, которые я пытаюсь загрузить, используя поведение Containable
в CakePHP. Большинство из них прекрасно работает.Containable Nested models
Однако одна модель, которая имеет hasMany
отношение только возвращает 1 объект:
$article = $this->News->find('first',array(
'conditions'=>array('News.id'=>$id),
'contain' => array(
'Newslayout',
'Newspicture'=> array(
'NewspicturesProduct' => array(
'Product' => array(
'Brand',
'Category'
)
)))
));
Объект только загружается один раз отношение Newspicture hasMany NewspicturesProduct
При входе в систему запросов, я получаю следующее:
SELECT `NewspicturesProduct`.`id`, `NewspicturesProduct`.`x`, `NewspicturesProduct`.`y`, `NewspicturesProduct`.`product_id`, `NewspicturesProduct`.`newspicture_id`, `NewspicturesProduct`.`w`, `NewspicturesProduct`.`h` FROM `edclondon`.`newspictures_products` AS `NewspicturesProduct` WHERE `NewspicturesProduct`.`newspicture_id` = 3
Что дает мне 3 результата (ов) в phpMyAdmin
. Но только 1 в отладить CakePHP в:
'Newspicture' => array(
(int) 0 => array(
'id' => '3',
'news_id' => '2',
'newspicture_file_path' => '5022443f-ddf8-4115-ae57-618e9d60b047.jpg',
'newspicture_file_size' => '1232546',
'order' => null,
'NewspicturesProduct' => array(
'id' => '1',
'x' => '0.180664',
'y' => '0.295312',
'product_id' => '3',
'newspicture_id' => '3',
'w' => '0.286133',
'h' => '0.478125',
'Product' => array(
'id' => '3',
//....
'Brand' => array(
'id' => '6',
//...
),
'Category' => array(
'id' => '6',
//....
)
)
)
)
При получении Newspictures
объекта, а затем извлечение News
объекта, я получаю все 3 NewspicturesProduct
объектов.
Но как вы можете знать, 'Newspicture.id' в том же запросе, в котором вы извлекая' News.id' –