문제

I am using cakephp 2.1 and defined 3 tables as follows.

   `industries(id, name);`
   `movies(id, name, industry_id),` 
   `trailers(id, name, movie_id);`

I want to paginate the trailers for particular industry. So the code I have written is below:

  $this->paginate = array(
                    'Industry' => array(
                        'contain' => array(
                            'Movie' => array(
                               'order' => 'Movie.release DESC', 
                               'Trailer' => array(
                                  'conditions' => array(
                                       'Trailer.id !=' => $trailer_id
                                   )
                                )
                             )
                         ), 
                         'conditions' => array(
                             'Industry.id' => $id
                         )
                      )
                  );

If I would specify 'limit' for 'Trailer', I get correct number of results but some null array for a movie which doesn't contain any trailers. Please help me to get the number of specified limit of trailers for particular industry. The work will be most appreciated.

도움이 되었습니까?

해결책

It looks to me like you've got your contain key in the wrong place. It should be defined before the models.

<?php
$this->paginate = array(
  'contain' => array(
    'Industry' => array(
      'Movie' => array(
        'order' => 'Movie.release DESC', 
        'Trailer' => array(
          'conditions' => array(
            'Trailer.id !=' => $trailer_id
          )
        )
      )
    )
  ),
    'conditions' => array(
      'Industry.id' => $id
  )
);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top