Trying to get along with Sphinx/Thinking Sphinx for the first time.
I've got my models defined as follows (simplified):
class Branch < ActiveRecord::Base
has_many :salesmen, :class_name => "User"
has_many :leads, :through => :salesmen
end
class User < ActiveRecord::Base
belongs_to :branch
has_many :leads, :foreign_key => "owner_id"
end
class Lead < ActiveRecord::Base
belongs_to :owner, :class_name => "User"
define_index do
indexes company_name
indexes :name, :sortable => true
has owner.branch_id, :as => :branch_id
indexes [owner.last_name, owner.first_name], :as => :owner_full_name, :sortable => true
end
end
Anytime I call
Branch.first.leads.search
I get
RuntimeError: Missing Attribute for Foreign Key branch_id
What am I doing wrong?