0

We are using thinkingtank gem and having trouble indexing model associations, even simple ones. For example, a profile belongs to an institution, which has a name – we would like to do something like:

class Profile < ActiveRecord::Base

#model associations

  define_index do
    indexes institution(:name), :as => :institution_name
  end

end

but that doesn't work. This must be very simple – what am I doing wrong?

Cory Schires
  • 2,146
  • 2
  • 14
  • 26

1 Answers1

2

a possible solution to this issue would be adding a method returning the element to index. For the profile.institution.name case:

# profile.rb
# ...
belongs_to :institution
# ...
define_index do
  indexes institution_name  
end 
def institution_name
  self.institution.name
end
# ...

Also the ", :as => ..." syntax is not supported on thinkingtank.

I would also recommend giving a try to Tanker: https://github.com/kidpollo/tanker

Regards.

Adrian

Adrian
  • 286
  • 2
  • 5
  • Thanks for the help. Using a virtual attribute works (didn't try it myself since the thinking_tank doc claims to mirror thinking_sphinx which only supports searches thru database columns). The best advice (as you suggested) is to use tanker. I ended up going with that. The API seems more powerful, is definitely cleaner and has way better documentation. Definitely use tanker rather thinking_tank. – Cory Schires Apr 12 '11 at 02:26