I am trying to search using an array of strings in my where clause.
The array is generated by splitting the string contained within param[:q][:genres_name_cont] like this:
params[:q][:genrearray] = params[:q][:genres_name_cont].split
For example, if 'Rock Blues' is entered in the genre field, params[:q][:genrearray] = ["Rock", "Blues"].
Giving me the array which I then use in my where clause:
@bands = Band.joins(:genres).where("genres.name IN (?)", params[:q][:genrearray])
However, the SQL generated doesn't seem to be searching through an array like I would expect:
SELECT DISTINCT "bands".* FROM "bands" LEFT OUTER JOIN "bands_genres" ON "bands_genres"."band_id" = "bands"."id" LEFT OUTER JOIN "genres" ON "genres"."id" = "bands_genres"."genre_id" WHERE "genres"."name" ILIKE '%Rock Blues%'
Rather than ' ILIKE '%Rock Blues%'' I would be expecting to see something like ' IN ('Rock','Blues')'
Thanks in advance to anyone who can help.