We were using below scope for ordering of our Payments which have a field 'number' of the like "PAY9994", "PAY9995", "PAY9996" etc.
scope :order_by_number, ->{order('number DESC')}
But we realized that it won`t work after our Payment number crosses "PAY9999". I could have used below scope, had it been a pure string of integers, but the prefix "PAY" is creating problems.
scope :order_by_number, ->{order('number::integer DESC')}
Any solution?