A
A
Alexander Petrov2018-09-27 21:25:43
Ruby on Rails
Alexander Petrov, 2018-09-27 21:25:43

What is the correct way to make a request in rails?

The task as a whole is very simple, but I don’t understand how to do it.
There are goods. They have a price. Some have a price with a "On Request" sign. Accordingly, the price and on_request fields. If price is greater than zero, then on_request=false. If price is zero, then on_request=true.
You need to sort by price, but always have products with the value on_request=true at the end of the list.
This must be one mysql query, since I use a page using kaminary.
It turns out that if I do order(price: :desc), then everything is OK, the highest prices are first, with zero (according to on_request) at the end. But if I do order(price: :asc), then the logic breaks down and on_requst climbs ahead, since they have price=0, how can I take the values ​​with on_request=true to the end in this situation?
Fuh .... I hope I made it more or less clear .... Thank you very much in advance, knowledgeable people!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Demidenko, 2018-09-27
@Mirkom63

order(on_request: :asc, price: :asc)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question