> You'd probably be best off creating a view (in the database, not a
> Cake view) to do this. Off the top of my head, the query would use a
> self join to grab the most recent record for each client. With proper
> indexing, it should be fairly efficient.

That seems like overkill to me, it's a simple and common query with a
little processing of the data. As long as the requests are paginated
it should never be an issue.

Hth,

j



>
> On Fri, Sep 11, 2009 at 3:42 PM, sindbad <[email protected]> wrote:
>>
>> Okay,
>>
>> thanks for your reply but from where I get the $id. This should be
>> Client.id but... this query selects only one row but I need to select
>> only one row for each client. I have 1000 clients and 21290 reports.
>> For every client I need to select the date of last report.
>>
>> On 11 sep., 21:52, Miles J <[email protected]> wrote:
>>> Well you would have to grab the last date. Heres a query, assuming you
>>> followed cake conventions.
>>>
>>> $result = $this->Report->find('first', array(
>>> 'fields' => 'Report.created',
>>> 'order' => 'Report.id DESC',
>>> 'conditions' => array('Report.client_id' => $id)
>>> ));
>>>
>>> Then echo it in the view: echo $result['Report']['created'];
>>>
>>> On Sep 11, 11:42 am, sindbad <[email protected]> wrote:
>>>
>>> > Hi,
>>>
>>> > first of all I want to say that I'm new to cake but with a little help
>>> > from http://book.cakephp.org and Google I've made a simple application for
>>> > managing clients and reports for the clients.
>>> > Each client has many raports. Now, in the index view of the clients I
>>> > need to show the date of last report. This is what I don't know how to
>>> > do it.
>>> > I'll be glad if you could tell me how to select only the date of the
>>> > last report for each of my clients.
>>> > Thanks.
>> >
>>
>
> >
>

-- 

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