bezzoon
bezzoon

Reputation: 2019

Ruby on Rails Where clause less than greater than

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

Answers (2)

xdazz
xdazz

Reputation: 160843

Use a range object.

.where(age: 5..50)

Or you could write

.where('age BETWEEN 5 AND 20')

Upvotes: 20

GAURAV SETH
GAURAV SETH

Reputation: 222

You can use operator also

.where("id >= ? and id <=  ?",5,20)

Upvotes: 5

Related Questions