I was excited to find in Link2.php that getBeans can take parameters to filter the beans that are retrieved.
I want to get the latest related record in code.
I was hoping to get it by ordering by date_modified and using a limit of 1
$filter = array(
'order_by'=>'date_modified desc',
'limit' => '1'
);
$bean = $recordBean->$link->getBeans($filter)
Similarly to what I would expect from a query like
select * from accounts order by date_modified desc limit 1
But it's not giving me the result I expected. It seems to be getting one seemingly random record and ignoring the sort.
I can get records newer than a given date by adding a where clause so the parameters are indeed being considered.
$filter = array(
'where' => array(
'lhs_field' => 'date_modified',
'operator' => '>=',
'rhs_value' => $date)
);
Any thoughts on ways to get the latest without having to get them all, sort them and then get one?
I'm trying to limit how much data I pull, there could be thousands of related records.
thanks,
Francesca