filter based on the latest date

Hi all,

I have a table called product_stock.

It has the fields product_name, stock and stock_date.

I want to modify my search so that when i filter a product only the latest stock is filtered i.e i want the product stock based on the latest stock_date.

Can anybody tell me how to do this?

Thanks.

filter in search? you mean CGridView or just normal CActiveRecord::findAll() ?

i mean CGRIDview in the advanced search

you can find a method in AR model called search, and it has lines like belows:


$criteria->compare('stock',$this->stock ,true);

$criteria->compare('stock_date',$this->stock_date,true);

$criteria->compare('product_name',$this->product_name,true);

and after add a line like


$criteria->compare('stock',$this->stock ,true);

$criteria->compare('stock_date',$this->stock_date,true);

$criteria->compare('product_name',$this->product_name,true);

$criteria->order = 't.stock_date DESC';