Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RoR as#U json调用丢失的数据';数据库中有什么_Json_Ruby On Rails 4_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Json,Ruby On Rails 4,elasticsearch" /> elasticsearch,Json,Ruby On Rails 4,elasticsearch" />

RoR as#U json调用丢失的数据';数据库中有什么

RoR as#U json调用丢失的数据';数据库中有什么,json,ruby-on-rails-4,elasticsearch,Json,Ruby On Rails 4,elasticsearch,使用rails 4.1.8、ruby 2.2、mysql、elasticsearch rails 5.0.4、elasticsearch 5.2。选择器模型上的selectors字段作为json存储在varchar列中,出于某种原因,当我使用as_json加载一个位置及其关联的选择器时,当我知道列中有数据时,selectors字段返回为nil 选择器表: create table Selectors do t.text selectors t.text selectors_othe

使用rails 4.1.8、ruby 2.2、mysql、elasticsearch rails 5.0.4、elasticsearch 5.2。选择器模型上的selectors字段作为json存储在varchar列中,出于某种原因,当我使用as_json加载一个位置及其关联的选择器时,当我知道列中有数据时,selectors字段返回为nil

选择器表:

create table Selectors do 
   t.text selectors
   t.text selectors_other
   t.references location
   t.timestamps
end
我最近添加了弹性搜索,因此该模型具有:

settings index: {
   analysis: {
      analyzer: {
         selector_analyzer: {
            type: :standard,
            stopwords: ["some","words","here"]
         }
      }
   }
}

mapping do
   indexes :selectors, {analyzer: :selector_analyzer}
   indexes :selectors_other, {analyzer: :selector_analyzer}
end

def as_indexed_json(options={})
   {
      'id' => id,
      'selectors' => selectors,
      'selectors_other' => selectors_other
   }
end
我为获取视图的数据所做的调用是

Location.find(<id>).as_json(:include => [:selector, :response])
Location.find().as_json(:include=>[:selector,:response])
我期望的每个字段都在json中,所有数据都在那里,除了选择器字段是nil。我知道有数据,因为如果我这样做:

loc = Location.find(<id>)
loc.selector
loc=Location.find()
位置选择器
选择器字段不是零。我尝试向选择器模型添加as_json方法,但没有任何效果。我最近所做的唯一更改是将选择器模型添加到Elasticsearch索引中。我使用IndexManager创建了一个具有多种类型的索引,并创建了一个用于部署和重新索引的rake任务。唯一的区别是该字段存储为json,但它以前工作正常


任何想法、建议等都将不胜感激,因为我想不出任何可能导致字段为零的东西。

找出了导致字段为零的原因,而不是导致问题的原因

我添加了一个方法来在更新选择器字段时操作json,在该方法中,我有一行

sel_hash = JSON.parse(self.selectors)
IDE无法解析self.Selector,因此我添加了

attr_accessor :selectors
由于某种原因,该行导致选择器字段为零,如图所示