Reputation: 634
How can I dismiss the returned records which are LIKE
those from an array.
At the moment I can filter my records only by a string, but I would like to pass an array of strings. Is it possible? And how?
array = ['test', 'test1', 'test2']
I would like something similar with the below query because name
can contain a string with multiple words.
Model.where.not('name like ?', "%caps%")
Upvotes: 0
Views: 55
Reputation: 33552
If you are using Rails 4,you can do like this:
Model.where.not(name: ['test','test1','test2'])
If you want use with like
then you have do like this
@model = Model.where('name like ?', "%caps%") #Retrieving all records like `caps`
@model1 = Model.where('name not in (?)', @model) #Excluding the records in `@model` and gives you the remaining
Upvotes: 1
Reputation: 714
Try this,
array = ['test', 'test1', 'test2']
Model.where('name not in (?)', array)
Upvotes: 3