我有以下情况:作品有一个属于 ImageGroup 的图像。
如果我这样做:
$works = $this->Work->find('all', array(
'contain' => array(
'PreviewImage' => array(
'fields' => array('PreviewImage.id', 'PreviewImage.filename', 'PreviewImage.alt'),
'ImageGroup' => array(
'fields' => array('ImageGroup.id')
)
)
)
));
我会得到这个:
array(
(int) 0 => array(
'Work' => array(
'id' => '1',
'title_us' => 'Work Title',
'title_de' => 'Arbeit Titel',
'alias' => 'work-title',
'pdf_id' => '1',
'date' => '2013-10-08 10:36:00',
'title_graphic_us_id' => '1',
'title_graphic_de_id' => '2',
'body_us' => 'English Content',
'body_de' => 'Deutscher Inhalt',
'preview_image_id' => '3',
'preview_us' => 'English Preview Text',
'preview_de' => 'Deutscher Vorschau Text',
'work_layout_id' => '2',
'state_id' => '1'
),
'PreviewImage' => array(
'id' => '3',
'filename' => 'preview_image.png',
'alt' => 'Preview Image',
'image_group_id' => '2',
'ImageGroup' => array(
'id' => '2'
)
)
)
)
但是,如果我试图通过以下方式减少工作领域:
$works = $this->Work->find('all', array(
'fields' => array(
'Work.id'
),
'contain' => array(
'PreviewImage' => array(
'fields' => array('PreviewImage.id', 'PreviewImage.filename', 'PreviewImage.alt'),
'ImageGroup' => array(
'fields' => array('ImageGroup.id')
)
)
)
));
我突然不再在 PreviewImage 中获得 ImageGroup,请参见此处:
array(
(int) 0 => array(
'Work' => array(
'id' => '1'
),
'PreviewImage' => array(
'id' => '3',
'filename' => 'preview_image.png',
'alt' => 'Preview Image',
'image_group_id' => '2'
)
)
)
我不明白为什么,你知道吗?