I'm working on a movie website project. I need to limit 5 reviews per movie page.
$this->Movie->find('first', array(
'conditions' => array('Movie.url' => $req ), // URL to fetch the required page
'recursive' => 1
));
Using the above code I'm getting 1 movie details and all(almost 20 for now) the reviews related to that movie. So how can I limit the reviews to 5 ?
I think no one knows how to solve, I found the some way that I can solve it temporarily. Please someone tell me about the best practice.
$movie = $this->Movie->find('first', array(
'conditions' => array('Movie.url' => $req ),
'recursive' => 0
));
$this->loadModel('MovieReview');
$movieReview = $this->MovieReview->find('all',array(
'conditions' => array('MovieReview.movie_id' => $movie['Movie']['id'] ),
'limit' => 5,
'recursive' => -1
));
$movie['MovieReview'] = $movieReview;
If someone needs to answer this, pls answer the best practice.