ruby on rails - Thinking Sphinx - RuntimeError: Missing Attribute for Foreign Key -
Spinks / thinkers are trying to get the first time with the Sphinx.
Model defined as (Simplified):
class branch : Salesman and Class User & lt; ActiveRecord :: Base is_to: The branch has_many: clues,: foreign_key => "Owner_id" end class lead & lt; ActiveRecord :: Base is_to: Owner, class_name = & gt; "User" defined_ index index india company_name index: name,: sortable = & gt; True is owner.branch_id ,: as in => : Branch_id Index [owner.last_name, owner.first_name] ,: as = & gt; : Owner_full_name ,: sortable = & gt; True End Closing
Anytime I call
branch. First.les.search I get it
What am I doing wrong? The problem is that thinking spinks as a feature in your index will be branch_id < / Code> is required, so it can only restrict the results for the related branch (because you are searching within an association).
This is not clear from your institutions (or maybe I just need to sleep) whether the lead comes under the branch through the boss or even directly. If the former, Ben's suggestion might be correct, otherwise try adding the following to your define_index block:
in Branch_Ad, as: =; : Direct_branch_id An alternative approach after reading the comments, is to add the Leeds Association to its own search method at the branch. A vague attempt (you will need to debug, I'm sure):
is_key: clues ,: through = & gt; : Salesmen Def Search (* Args) option = args.extract_options! Option [: with] || = {} Option [: with]]: [branch_id] = proxy_owner.id args & lt; & Lt; Option Lead Search (* Args) End End Should be around the fact that you do not have direct reference to the branch from the lead. The only possible issue is that I'm not sure whether custom extensions are loaded before or after thinking of spinks. Give it a shot, see if it helps.
Comments
Post a Comment