0

I want to do exactly this but I want to do it in Cake PHP which makes things more complicated.

Here's what I have so far:

$results = $this->Model->find('first', array('conditions' => array('id' => $id), 
                                             'contain' => array('OtherModel' => array('limit' => 10)));

which limits the results of data from OtherModel to 10. This isn't quite what I want though.. I want to limit the results to the last 10 results.

Any ideas how you would do this?

Many thanks :).

Community
  • 1
  • 1
ale
  • 11,636
  • 27
  • 92
  • 149

1 Answers1

1

If I understand correctly, I think you are on the right track.

Add this to your find parameters:

'order' => 'id DESC' // or created or whatever field you want to reverse sort by

That combination with LIMIT will get the last x results.

Barry Chapman
  • 6,690
  • 3
  • 36
  • 64