我无法从数据库中找到正确的记录。这是我的查询:
@interested_individual = Profile.where('category_id = ?', @event.interests).all
category_id
是配置文件表中保存整数值的列,@event.interests
返回一个数组 ["1", "2", “3”]
我在这里想要的是获取 @event.interests
数组中存在其 category_id
的所有配置文件。
请让我知道解决方案。提前致谢
最佳答案
你真的不需要用 ?
和所有的东西手动编写绑定(bind)。
试试这个:
@interested_individual = Profile.where(category_id: @event.interests).all
如果您传入一个数组,Active Record 会为您将其转换为 category_id IN (?)
。
关于mysql - Rails where 子句将整数与数组匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32182593/