0

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'
            )
        )
)

同じ結果で異なる「DestinationIdiom」によって引き起こされた「DestinationPhoto」、「Destinations」の複数のインスタンスを取得したようですが、両方の「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 Controller には、次のものがあります。

        $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
    );
4

1 に答える 1

0

モデルの命名規則を使用します。Destinationの代わりに作りDestinationsます。

以下のように、実行時にモデルの関連付けをバインドします。

$this->paginate = array(
    'joins' => array(
        array(
            'table' => 'destinations',
            'alias'=>'Destination',
            'type' => 'LEFT',
            'conditions' => '`DestinationPhoto`.`destination_id` = `Destinations`.`id`'
        )),
    'limit' => 20,
    'recursive' => '2'
    );

    $this->DestinationPhoto->Destination->bindModel(array('hasMany' => array('DestinationIdiom' => array('className' => 'DestinationIdiom',
                                                                                                         'foreignKey' => 'destination_id'))), false);
    $result = $this->paginate('Destination');
    pr($result);
    die;
于 2014-02-19T04:32:43.660 に答える