在 Cake 中使用 Paginate 后得到以下结果:
array(
(int) 0 => array(
'DestinationPhoto' => array(
'id' => '1',
'name' => 'picture.jpg',
'destination_id' => '2'
),
'Destinations' => array(
'id' => '2',
'country_id' => '2'
),
'DestinationIdiom' => array(
'id' => '3',
'name' => 'TestName-1',
'description' => 'TestDescription',
'idiom' => 'English',
'destination_id' => '2'
)
),
(int) 1 => array(
'DestinationPhoto' => array(
'id' => '1',
'name' => 'picture.jpg',
'destination_id' => '2'
),
'Destinations' => array(
'id' => '2',
'country_id' => '2'
),
'DestinationIdiom' => array(
'id' => '4',
'name' => 'TestName-2',
'description' => 'TestDescription-2',
'idiom' => 'Spanish',
'destination_id' => '2'
)
)
)
似乎我在同一结果中得到了多个“DestinationPhoto”、“Destination”实例,由不同的“DestinationIdiom”引起,有可能将两个“DestinationIdiom”加入以显示为分页器的相同结果?喜欢
array(
(int) 0 => array(
'DestinationPhoto' => array(
'id' => '1',
'name' => 'huehuehuehuh.jpg',
'destination_id' => '2'
),
'Destinations' => array(
'id' => '2',
'country_id' => '2'
),
'DestinationIdiom' => array(
(int) 0 => array(
'id' => '3',
'name' => 'TestName-1',
'description' => 'TestDescription',
'idiom' => 'English',
'destination_id' => '2'
)
(int) 1 => array(
'id' => '3',
'name' => 'TestName-2',
'description' => 'TestDescription',
'idiom' => 'Spanish',
'destination_id' => '2'
)
)
)
)
在 DestinationPhoto 控制器中,我有以下内容:
$this->paginate = array(
'fields'=>array('DestinationPhoto.*','Destinations.*','DestinationIdiom.*'),
'joins' => array(
array(
'table' => 'destinations',
'alias'=>'Destinations',
'type' => 'LEFT',
'conditions' => '`DestinationPhoto`.`destination_id` = `Destinations`.`id`'
),
array(
'table' => 'destination_idioms',
'alias'=>'DestinationIdiom',
'type' => 'LEFT',
'conditions' => '`DestinationIdiom`.`destination_id` = `Destinations`.`id`'
)
),
'limit' => 20
);