0

我是 Rails 的新手。我有一个名为 OfflineExport 的模型。在表中我有这样的数据

#<OfflineExport id: 2, 
  parameters: 
      {"project_id"=>"3", 
       "type"=>"submissions", 
       "filters"=>{"task_type"=>"", 
       "corrections"=>"", "grade"=>"", 
       "min_duration"=>"", "after"=>"", 
       "max_duration"=>"", "reviews"=>"", 
       "before"=>""}, 
  "send_email"=>"true", 
  "options"=>{"offline_record_id"=>2}}>

我试图在 where 子句中获取参数 [“project_id”]

 OfflineExport.where("parameters[project_id] = '3'")

但我收到如下错误:

ActiveRecord::StatementInvalid: PGError: ERROR:  cannot subscript type text because it is not an array

谁能帮我解决这个问题?

4

1 回答 1

0

您的模型中似乎有一个序列化列。像这样的东西:serialize :parameters。这意味着数据以不易于阅读的格式存储在数据库中,这导致您无法对其进行查询。和这里一样

解决方案:提取您要查询的字段,并为其创建一个列。

于 2012-11-10T16:09:49.803 回答