假设以下型号:
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
如何在thinking_sphinx
中对此进行索引Order.tickets.first.technician.name
我明白我能做到
define_index do
indexes tickets.technician_name, :as => :technician_name
end
如果technician_name是故障单表中的列,但事实并非如此。票证表只有外键。
答案 0 :(得分:1)
根据索引方法的文档:
您应该可以浏览以下关联:
define_index do
indexes tickets.technician.name, :as => :technician_name
end