【问题标题】:Rails includes with where condition on jsonb fieldRails 在 jsonb 字段中包含 where 条件
【发布时间】:2021-08-27 20:18:10
【问题描述】:

我有一个名为 metadatajsonb 类型的字段,它是 OrderItem 模型的字段。

我想获取包含带有特定元数据的 order_item 的每个订单。我当前的代码如下所示:

Order.includes(:order_items)
     .where('order_items.metadata @> ?', { category: 'regular' })

这会产生以下错误:

ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "order_items")

【问题讨论】:

  • 你应该使用joins 而不是includes
  • 这行得通,谢谢!

标签: ruby-on-rails postgresql


【解决方案1】:

使用joins 而不是includes

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-11
    • 1970-01-01
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    • 2018-07-25
    相关资源
    最近更新 更多