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
精彩评论