AdvanceInBeginning
AdvanceInBeginning

Reputation: 99

active record search in a range, but outer way around

noob here.

i am asking for an way to search in an range, that gets all records, that is not in the range.

example of the normal way:

Customer.where(body_size: 160..210)

how i want it:

Customer.where(body_size: !160..210)

so, i get all records that is lower than 160 and bigger than 210. Dos provided rails something like the code above?

Basically i want something like this:

Customer.where("body_size < ? AND body_size > ?", 160, 210)

Upvotes: 0

Views: 41

Answers (1)

zwippie
zwippie

Reputation: 15515

Use where.not:

Customer.where.not(body_size: 160..210)

This translates to the following SQL:

SELECT * FROM customers  WHERE (NOT (body_size BETWEEN 160 AND 200))

Upvotes: 2

Related Questions