0

认为 sphinx 索引很好,并且查找在我的属性上效果很好。但是,我保存模型实例的尝试崩溃了。

class Location < ActiveRecord::Base
  has_many :operation_intervals_locations
  has_many :operation_intervals, :through => :operation_intervals_locations

  define_index "location" do
    # indexes here...

    # tried this syntax
    has operation_intervals(:start_int), :type => :integer 
    has operation_intervals(:end_int), :type => :integer
    has operation_intervals(:days_int), :type => :integer

    # and this one
    has operation_intervals.start_int, :type => :integer 
    has operation_intervals.end_int, :type => :integer
    has operation_intervals.days_int, :type => :integer
  end
end


class OperationInterval < ActiveRecord::Base
 attr_accessible :start_int, :end_int, :days_int  
end

每当我执行以下操作时:

Location.search("foo") # get the search initialized
l = Location.first
l.name = "bar"
l.save(:validate => false)

我得到以下信息:

# joining is working just fine
OperationInterval Load (0.3ms)  SELECT `operation_intervals`.* FROM `operation_intervals` INNER JOIN `operation_intervals_locations` ON `operation_intervals`.`id` = `operation_intervals_locations`.`operation_interval_id` WHERE `operation_intervals_locations`.`location_id` = 1

# here's where I'm getting my crash
NoMethodError: undefined method `end_int' for #<ActiveRecord::Relation:0xe048450>
from /usr/local/rvm/gems/ruby-1.9.3-p194@rails326/gems/activerecord-3.2.6/lib/active_record/relation/delegation.rb:45:in `method_missing'

编辑:我正在使用延迟的增量 - 延迟的工作。我认为问题正在发生,因为thinking_sphinx 正试图将工作推到队列中。

4

1 回答 1

0

好的.. 思考狮身人面像适用于多对多的关系

线

has operation_intervals.days_int, :type => :integer

应该有:type => :integer,因为一个位置可以有多个 operation_intervals 并且真正的类型是数组!

改用此代码将解决问题:

has operation_intervals.days_int
于 2012-06-21T18:24:40.810 回答