Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 420
bezzoon Avatar asked Jan 22 '14 06:01

bezzoon


2 Answers

Use a range object.

.where(age: 5..50)

Or you could write

.where('age BETWEEN 5 AND 20')
like image 172
xdazz Avatar answered Nov 16 '22 01:11

xdazz


You can use operator also

.where("id >= ? and id <=  ?",5,20)
like image 5
GAURAV SETH Avatar answered Nov 16 '22 02:11

GAURAV SETH