Reputation: 129
I have relations like this:
On the project page, I want to display:
So far, I have this:
$this->set('rates', $this->Rate->find('all', array(
'conditions' => array('Property.project_id' => $id),
'fields' => array('Rate.id', 'Rate.rate', 'Rate.floor_rise', 'Property.id'),
'order' => array('Rate.created DESC')
)));
This gives all rates for the respective property, but I only want the latest rate.
How should I do this query?
Upvotes: 0
Views: 183
Reputation: 2025
$this->set('rates', $this->Rate->find('first', array(
'conditions' => array('Property.project_id' => $id),
'fields' => array('Rate.id', 'Rate.rate', 'Rate.floor_rise', 'Property.id'),
'order' => array('Rate.created DESC')
)));
Upvotes: 2
Reputation: 3415
Change 'all'
to 'first'
in your find, and as you already have a good 'order'
you should be fine.
Upvotes: 3