Reputation: 2019
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?
Upvotes: 8
Views: 9927
Reputation: 160843
Use a range object.
.where(age: 5..50)
Or you could write
.where('age BETWEEN 5 AND 20')
Upvotes: 20