Hey Pat,

Man, you are good. And fast, too! Thanks a lot for helping me with
this. Your solution worked like a charm!

BTW, I'm confused about it barfing on 'act', too. But I'm pretty sure
that was the problem. To illustrate:

This is my association:

  belongs_to :act, :class_name  => 'Activity::Act',
                           :foreign_key => 'activity_act_id'

And this is my define_index block:

  define_index do
    indexes text
    has act.politician_pol_id, :as => :politician
  end

And this is what happens when I do a 'rake ts:rebuild':
Generating Configuration to /home/larry/RubyMineProjects/stupid-
tuesday/config/development.sphinx.conf
rake aborted!
undefined method `politician_pol_id' for nil:NilClass
/home/larry/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/
whiny_nil.rb:52:in `method_missing'
/home/larry/RubyMineProjects/stupid-tuesday/app/models/activity/
comment.rb:43

As you can see, the 'act' association is nil, even though it is
defined before the 'define_index' block. To test my theory, this is
what I had - workng - before your more elegant solution:

# Define the same association using 'th_sp_act' instead of 'act'
belongs_to :th_sp_act, :class_name  => 'Activity::Act',
                                  :foreign_key => 'activity_act_id'

When I did that, this worked:
  define_index do
    indexes text
    has th_sp_act.politician_pol_id, :as => :politician
  end

Regardless, thanks again!!!

-- Larry

On May 25, 11:15 pm, Pat Allan <[email protected]> wrote:
> Hi Larry
>
> I'm not sure why 'act' is a reserved word - I would expect the following to 
> work:
>
>  has act.pol_id, :as => :politician
>
> Otherwise, though, the trick is that you're starting with a symbol, and so 
> you need to use the assoc method:
>
>  has assoc(:act).pol_id, :as => :politician
>
> Cheers
>
> --
> Pat
>

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to