I have a rails model call MentorData and it has an attribute called os_usage
. The oses are stored in an array like so ['apple', 'linux']
.
To recap:
$ MentorData.first.os_usage
=> ['apple', 'linux']
I am looking to be able to query the data for all MentorData that includes the os_usage of apple
, but when I search MentorData.where(os_usage: 'apple')
I only get the mentors who can only use apple and not apple and linux. I need to search in some way that checks if apple is included in the array.
I have also tried the following.
MentorData.where('os_usage like ?', 'apple’)
MentorData.where('os_usage contains ?', 'apple’)
MentorData.where('os_usage contains @>ARRAY[?]', 'apple')
Is it possible to query data in ActiveRecord by attributes that have an array or items?
The database is on Postgres if that helps in providing a more raw search query.