> Not working. It shows me only the last date of the last report.

There are a few ways to accomplish this.

1. Use Containable to limit the Reports you retrieve.

// Attach Containable if not already attached
$this->Client->Behaviors->attach('Containable');

// Grab data
$this->data = $this->Client->find('all', array(
        'contain'=>array(
                'Report'=>array('limit'=>1)
        )
));

// Loop over in view
foreach($this->data as $row):
        echo 'name: '.$row['Client']['name'];
        if (isset($row['Report'][0])):
                echo 'last report created: '.$row['Report'][0]['created'];
        endif;
endforeach;

2. Or get all the data as per normal and pull out the most recent report date

// Alteratively you could grab all data
$this->data = $this->Client->find('all', array(
        'contain'=>array(
                'Report'=>array('limit'=>1)
        )
));

// And get the last record in the view
foreach($this->data as $row):
        echo 'name: '.$row['Client']['name'];
        if (isset($row['Report'])):
                echo 'last report created:
'.$row['Report'][count($row['Report'])-1]['created'];
        endif;
endforeach;

3. Use the afterFind model callback in Client to grab the most recent
date and add it to the client data

public function afterFind($results) {
        // no data
        if (empty($results))
                return $results;
        
        // no report data
        if (!isset($results['Report']))
                return $results;
                
        // loop over
        foreach($results as &$row) {
                $row['Client']['most_recent_report_created'] =
$row['Report'][count($row['Report'])-1]['created'];
        }
        
        return $results;
}

hth

jon


-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to