I made a strategic mistake when developing database architecture on my Rails app
Now I have to implement sorting by price feature using
MyModel.order('price DESC')
price is a string type in the database, which cause 50 to be greater than 2000 for example
Are there any ways to implement such .order()
without changing database structure?
EDIT:
I switched to correct type (integer) for price column. It took me an hour only to refactor.
ORDER BY price::float
. – Turnsole