I have an array of value :
words = ['foo', 'bar', 'baz']
I want autogenerate a where clause with LIKE (and not "IN").
What I do for now :
words = params[:content].split(' ').map { |w| "%#{w.strip}%" }
where = []
words.size.times do
where << 'name LIKE ?'
end
tags = Tag.where(where.join(' OR '), *words)
the correct request SQL is generate :
SELECT `tags`.* FROM `tags` WHERE (name LIKE '%foo%' OR name LIKE '%bar%' OR name LIKE '%baz%')
but it's not realy nice way...
when I want compare array values with equals, we can just do :
Tag.where(name: words)
There is a possibility to do same thing but not generate IN, but multiple OR LIKE "%VALUE%" ? How?