【问题标题】:find_or_create_by in the ruby jsonb columnruby jsonb 列中的 find_or_create_by
【发布时间】:2022-08-15 12:49:40
【问题描述】:

我们有find_or_create_by 用于Ruby 中的jsonb 吗? 我想要一个标题为something 的项目

{ title: {en: \'something\', de: \'something\' }

代替

Model.where(sanitize_sql(\"title->> \'#{I18n.locale}\' ILIKE ?\"), \'something\')

    标签: ruby-on-rails ruby activerecord jsonb ruby-on-rails-6.1


    【解决方案1】:

    不,我们没有那个功能。

    对于 PostgreSQL 数据库,Rails 让位于 JSON 和 JSONB 的 PostgreSQL 函数和运算符,并且不对这些函数和任何访问方法分层

    而且一般ActiveRecord::Type::Json只能序列化和反序列化。

    【讨论】:

      猜你喜欢
      • 2020-05-02
      • 2018-10-02
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-13
      • 1970-01-01
      相关资源
      最近更新 更多