How can I sort the returned values of a collectionBean fetch. I have a module that stores various discounts based on quantity and I need the equivalent of select ... from ... where producttemplate_id_c=... and account_id_c=..... and ... order by quantity desc limit 1
custom_amount_prices.fetch({
fields: ["price","quantity"],
filter: [
{
producttemplate_id_c: {'$equals': product_id},
},
{
account_id_c: {'$equals': billing_id}
},
{
quantity: {'$lte': quantity}
},
{
start_date: {'$lte': current_date_mysql}
},
{
end_date: {'$gte': current_date_mysql}
}
],
success:function(row)
{
console.log(row);
if (!_.isEmpty(row) && !_.isEmpty(row.models) && !_.isEmpty(row.models[0]))
{
//stuff
}
},
...........................
The above code does what I want, just without the order by quantiy limit 1 part. I could write a REST api, but I am curious if this can be solved by the inbuilt fetch stuff