我有一个rails模型名为MentorData,它有一个名为os_usage
的属性.操作系统存储在类似so ['apple', 'linux']
的数组中.
总结一下:
$ MentorData.first.os_usage
=> ['apple', 'linux']
我希望能够查询所有导师数据,包括os_使用apple
的数据,但当我搜索MentorData.where(os_usage: 'apple')
时,我只得到只能使用apple而不能使用apple和linux的导师.我需要以某种方式搜索,以判断数组中是否包含苹果.
我也try 了以下方法.
MentorData.where('os_usage like ?', 'apple’)
MentorData.where('os_usage contains ?', 'apple’)
MentorData.where('os_usage contains @>ARRAY[?]', 'apple')
是否可以通过具有数组或项的属性查询ActiveRecord中的数据?
如果这有助于提供更原始的搜索查询,则数据库位于Postgres上.