diff --git a/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb b/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb index 6a165f287..d861f78a2 100644 --- a/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb +++ b/lib/thinking_sphinx/active_record/association_proxy/attribute_finder.rb @@ -29,7 +29,7 @@ def indices @indices ||= begin configuration.preload_indices configuration.indices_for_references( - *@association.klass.name.underscore.to_sym + *ThinkingSphinx::IndexSet.reference_name(@association.klass) ).reject &:distributed? end end diff --git a/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb b/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb index 16120bb71..38e1a7bed 100644 --- a/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb +++ b/lib/thinking_sphinx/active_record/callbacks/update_callbacks.rb @@ -35,7 +35,7 @@ def indices end def reference - instance.class.name.underscore.to_sym + ThinkingSphinx::IndexSet.reference_name(instance.class) end def update(index) diff --git a/lib/thinking_sphinx/index_set.rb b/lib/thinking_sphinx/index_set.rb index 185f49bef..5d3ad779f 100644 --- a/lib/thinking_sphinx/index_set.rb +++ b/lib/thinking_sphinx/index_set.rb @@ -1,5 +1,10 @@ class ThinkingSphinx::IndexSet include Enumerable + + def self.reference_name(klass) + @cached_results ||= {} + @cached_results[klass.name] ||= klass.name.underscore.to_sym + end delegate :each, :empty?, :to => :indices @@ -63,7 +68,7 @@ def indices_for_references def references options[:references] || classes_and_ancestors.collect { |klass| - klass.name.underscore.to_sym + ThinkingSphinx::IndexSet.reference_name(klass) } end diff --git a/lib/thinking_sphinx/middlewares/sphinxql.rb b/lib/thinking_sphinx/middlewares/sphinxql.rb index 5592a6217..d9cf4d225 100644 --- a/lib/thinking_sphinx/middlewares/sphinxql.rb +++ b/lib/thinking_sphinx/middlewares/sphinxql.rb @@ -82,7 +82,7 @@ def descendants_from_tables def indices_match_classes? indices.collect(&:reference).uniq.sort == classes.collect { |klass| - klass.name.underscore.to_sym + ThinkingSphinx::IndexSet.reference_name(klass) }.sort end