我知道在serialize
中搜索不好,但是我遇到了这个问题。在rails中搜索序列化列
我得到了一个叫做问题模型,并包含一个序列化列assignments
id question_set_id assignments
1 1 {"12982": true, "12332": true}
2 2 {"12222": true, "12332": true}
3 3 {'11111': true}
而且我得到了一个阵列称为group_ids
group_ids = ["12982","12332"]
我需要找到谁包含至少一个group_id
记录assignments
。
所以,这个例子的结果应该是像
[
{
:id => 1,
:question_set_id => 1,
:assignments => {"12982": true, "12332": true}
},
{
:id => 2,
:question_set_id => 2,
:assignments => {"12222": true, "12332": true}
}
]
我已经试过
Question.where("assignments IS NOT NULL").where("assignments LIKE '%?%'", 12982)
这似乎工作,但如何应用一个数组?
而且根据这个answer,我试过
Question.where("assignments IS NOT NULL").where("assignments= ?", groups_ids.to_yaml)
但是,它返回一个空数组。
你使用哪个数据库(postrgesql/mysql)?你使用哪个序列化器(JSON,Hash,Custom)?哪种类型是您的序列化列(文本,JSON,hstore)? – slowjack2k
mysql,JSON和文本 –