So I want to do a ruby on rails query that is structured this way with a less than and greater than constraint.
self.order('random()')
.where(
friends: friend,
age: {minimum: 5, maximum: 20}
)
The above is how I imagine it to be done, being a ruby beginner. However this does not work. How can this be correctly achieved?
Use a range object.
.where(age: 5..50)
Or you could write
.where('age BETWEEN 5 AND 20')
You can use operator also
.where("id >= ? and id <= ?",5,20)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With