我正在使用 Rails 5 rc1 制作应用程序。Rails 5 支持 mysql 5.7 json 数据类型。
add_column :organizations, :external, :json
假设该列中的值如下:
+---------------------------+
| external |
+---------------------------+
| {"id": 10, "type": "mos"} |
+---------------------------+
要在外部列中搜索特定的“id”和“type”,我在 mysql 中使用以下查询:
select external from organizations where JSON_CONTAINS(external,'{"id": 10, "type": "mos"}') ;
现在,我想知道如何使用 rails 进行相同的查询。以下不起作用:
Organization.where("JSON_CONTAINS(external,'{"id": 10, "type": "mos"}')")
注意:我无法删除 json 文本周围的引号,因为它是查询的一部分。