【问题标题】:PG::UndefinedTable: ERROR: missing FROM-clause entry for tablePG::UndefinedTable: 错误: 缺少表的 FROM 子句条目
【发布时间】:2016-05-06 07:29:34
【问题描述】:

我有一个表A 有列name(string), email(sring) and details(json)。我想像这样使用 first_or_create:

A.where(:name => a.name, :email => a.email, :details => a.details).first_or_create

但这会产生以下错误:

PG::UndefinedTable: ERROR: missing FROM-clause entry for table "details"

如果我们有一个json类型的列,我们不能像上面那样查询吗?

【问题讨论】:

    标签: ruby-on-rails json database ruby-on-rails-4


    【解决方案1】:

    我想通了。事实证明,对于 JSON,查询将是这样的:

    A.where("name=? and email=? and details->>'key1'=? and details->>'key2'=?", a.name, a.email,a.details["key1"],a.details["key2"])

    http://edgeguides.rubyonrails.org/active_record_postgresql.html#json

    【讨论】:

      猜你喜欢
      • 2015-01-22
      • 2019-02-17
      • 2016-03-24
      • 2015-10-30
      • 2018-06-30
      • 2015-12-19
      • 1970-01-01
      • 2014-09-25
      • 1970-01-01
      相关资源
      最近更新 更多