gpt4 book ai didi

ruby-on-rails - 使用acts_as_taggable_on 查询错误表名来测试Thinking Sphinx

转载 作者:行者123 更新时间:2023-12-04 05:56:45 25 4
gpt4 key购买 nike

首先,事情的生产方面工作得很好,只有当我运行测试时才会出现错误。

正如标题中所述,我将 Thinking Sphinx 与 act_as_taggle gem 一起使用。以下是我正在使用的模型的一些片段:

class Special < ActiveRecord::Base
acts_as_taggable
acts_as_taggable_on :cuisines, :meals

...

define_index do
...
indexes cuisine_taggings.tag(:name), :as => :cuisine_tags, :facet => true
indexes meal_taggings.tag(:name), :as => :meal_tags
...
end

...

end

搜索看起来像这样:
Special.search("some query", {
:conditions => {:meal_tags => "dinner"} ,
:geo => coordinates,
:retry_stale => true,
:with => {
"@geodist" => 0.0..distance,
:timeframe => [1,2],
},
:page => page,
:per_page => Kaminari.config.default_per_page,
:order => "#{day} desc, @relevance DESC, @geodist ASC"
}

我看到的错误是这样的:
Mysql2::Error: Unknown column 'cuisine_taggings_specials.context' in 'where clause': SELECT `taggings`.`id` AS t0_r0, `taggings`.`tag_id` AS t0_r1, `taggings`.`taggable_id` AS t0_r2, `taggings`.`taggable_type` AS t0_r3, `taggings`.`tagger_id` AS t0_r4, `taggings`.`tagger_type` AS t0_r5, `taggings`.`context` AS t0_r6, `taggings`.`created_at` AS t0_r7, `tags`.`id` AS t1_r0, `tags`.`name` AS t1_r1 FROM `taggings` LEFT OUTER JOIN `tags` ON `tags`.`id` = `taggings`.`tag_id` WHERE `taggings`.`taggable_id` = 1 AND `taggings`.`taggable_type` = 'Special' AND (`cuisine_taggings_specials`.context = 'cuisines')

如您所见,查询试图定位“cuisine_taggings_specials”表,而不仅仅是 taggings 表。

每当我更改索引时,我都会在 dev 和 test 中重建索引。

就像我说的,生产和开发工作得很好,只有在我运行测试时。

最佳答案

我想知道它是否与测试环境生成配置时未填充多态数据有关。你如何运行测试? cucumber ,纯 capybara ,还是别的什么?

添加一些数据后,尝试重新生成配置,然后建立索引:

ThinkingSphinx::Test.stop  # if sphinx is already running?
ThinkingSphinx::Test.start # this generates config, indexes, and starts Sphinx.

当然,如果错误发生在您的设置之外,这没有帮助......因此第一个问题:)

关于ruby-on-rails - 使用acts_as_taggable_on 查询错误表名来测试Thinking Sphinx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9424573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com