我正在尝试对序列化列进行简单查询,您该怎么做?serialize :mycode, Array1.9.3p125 :026 > MyModel.find(104).mycode MyModel Load (0.6ms) SELECT `mymodels`.* FROM `mymodels` WHERE `mymodels`.`id` = 104 LIMIT 1 => [43565, 43402] 1.9.3p125 :027 > MyModel.find_all_by_mycode("[43402]") MyModel Load (0.7ms) SELECT `mymodels`.* FROM `mymodels` WHERE `mymodels`.`mycode` = '[43402]' => [] 1.9.3p125 :028 > MyModel.find_all_by_mycode(43402) MyModel Load (1.2ms) SELECT `mymodels`.* FROM `mymodels` WHERE `mymodels`.`mycode` = 43402 => [] 1.9.3p125 :029 > MyModel.find_all_by_mycode([43565, 43402]) MyModel Load (1.1ms) SELECT `mymodels`.* FROM `mymodels` WHERE `mymodels`.`mycode` IN (43565, 43402) => []
3 回答
Qyouu
TA贡献1786条经验 获得超11个赞
序列化数组以特定方式存储在数据库中,例如:
[1, 2, 3, 4]
in
1\n 2\n 3\n etc
因此查询将是
MyModel.where("mycode like ?", "% 2\n%")
在%和之间放置空格2。
- 3 回答
- 0 关注
- 559 浏览
添加回答
举报
0/150
提交
取消