Querying any member of a Postgres array type in Rails 4 -
everywhere looked there 2 examples
either
book.where("'history' = (subjects)")
to query book specific subject in subject array
or
book.where("subjects @> ?", '{'history', 'drama'}')
to query books subjects array has both history , drama
how query books has either history or drama or both?
at moment solving using
query = subject_list.map |subject| "'#{subject}' = any(subjects)" end.join(" or ") book.where(query)
Comments
Post a Comment