Only select newest record from joined table with CActiveDataProvider

Hi.

I use the following to select users and there payments. User has a HAS_MANY relation to Payment and Payment has a BELONGS_TO relation to User.

How can I make sure that I only check the newest payment record if there is more than one? Fx if there is two payment records and the oldest record match the “condition” but the newest don’t the user should not be included in the result.


$criteria = array(

  'condition'=>'status = "Paid" AND DATEDIFF(expires, NOW()) >= 0',

  'order'=>'expires',

  'with'=>'payments',

  'together'=>true,

);


$dataProvider=new CActiveDataProvider('User', array('criteria'=>$criteria));

Thanks! :)