I was a model Orderand Producta communication "many-to-many". So, the order of has_manyproducts, each of which has different prices.
Now I want to sort the orders with the maximum price of the product that the order has.
Here is my code:
@orders = Order.group(arel_table[:id]).
order(Product.arel_table[:price].maximum)
It works fine with the default ASC order, but when I sort it as a DESC order, for example:
@orders = Order.group(arel_table[:id]).
order(Product.arel_table[:price].maximum.desc)
I got an error:
undefined method `desc' for #<Arel::Nodes::Max:0x007fb2ab9104a0>
How to sort orders like DESC?
source
share