2012-06-21 3 views
0

스핑크스 인덱스는 내 속성에서 잘 작동한다고 생각합니다. 그러나 모델 인스턴스를 저장하려고하면 충돌이 발생합니다.인덱스를 통해 has_many를 사용하여 스핑크스를 생각하면 괜찮지 만 항목이 저장되는 경우

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/[email protected]/gems/activerecord-3.2.6/lib/active_record/relation/delegation.rb:45:in `method_missing' 

편집 : I 지연 델타 사용하고 - 지연 작업을. thinking_sphinx가 작업을 대기열로 밀어 넣으려고 할 때 문제가 발생했다고 생각합니다.

답변

0

이 좋아 .. 스핑크스를 생각하는 것은 많은 관계

라인에 많은 잘 작동

has operation_intervals.days_int, :type => :integer 

해야 위치가 여러 operation_intervals을 가질 수 있으며, 실제 타입이 배열 때문에하지:type => :integer있다!

has operation_intervals.days_int 
:이 문제를 해결할 것 대신에이 코드를 사용