【发布时间】:2021-09-28 15:48:34
【问题描述】:
我有一个带有 jsonb 列的下表配置文件
| item_type | object_changes |
|---|---|
| "Item" | [{"customer_id": [1, 5], "other_id": 1}, {"customer_id": [4, 5], "other_id": 2}] |
| "Item" | [{"customer_id": [3, 6], "other_id": 3}, {"customer_id": [3, 5], "other_id": 2}] |
我希望能够使用活动记录查询以查找所有 customer_id 为 5 的行。
我尝试了以下操作,但它不起作用
Profile.where("object_changes->'customer_id' @> '5'")
Profile.where("object_changes->'customer_id' @> ?::jsonb", [5].to_json)
Profile.where("? = ANY (object_changes->>'customer_id')", 5)
有谁知道我如何能够在 Ruby on Rails 中进行此查询。
我的 Rails 版本是 Rails 4.2,Ruby 版本是 2.4.10,我使用 postgres 作为我的数据库
【问题讨论】:
标签: ruby-on-rails ruby postgresql ruby-on-rails-4 activerecord