开发者

How do you drill through associations to create indexes for thinking_sphinx?

开发者 https://www.devze.com 2023-02-12 21:42 出处:网络
Assume the following models: class Order < ActiveRecord::Base belongs_to :customer has_many:line_items, :dependent => :destroy

Assume the following models:

class Order < ActiveRecord::Base  
  belongs_to :customer 
  has_many   :line_items, :dependent => :destroy  
  has_many   :tickets, :through => :line_items, :dependent => :destroy  
end  

class Ticket < ActiveRecord::Base
  has_many :items, :dependent => :destroy
  has_many :services, :through => :items
  has_many :line_items
  has_many :orders, :through => :line_items
  belongs_to :technician  
end  

class Technician < ActiveRecord::Base  
  has_many :tickets
  has_many :items, :through => :tickets
  accepts_nested_attributes_for :tickets, :items
end  

How do you index this in thinking_sphinx

Order.tickets.first.technician.name

I understand that I could do

  define_index do开发者_如何学JAVA
    indexes tickets.technician_name, :as => :technician_name
  end 

if technician_name is a column in tickets table, but it's not. tickets table only has foreign keys.


According to the documentation of the indexes method:

http://rdoc.info/github/freelancing-god/thinking-sphinx/master/ThinkingSphinx/Index/Builder#indexes-instance_method

You should be able to navigate through associations like:

 define_index do
     indexes tickets.technician.name, :as => :technician_name
 end 
0

精彩评论

暂无评论...
验证码 换一张
取 消