Hi Christian

I don't think it's an issue with the module naming (the first solution  
suggested). The issue is that the expected method for searching via  
Sphinx (or Ferret, Solr, etc) is 'search' - and that's what your  
relationship is called as well. One is always going to override another.

Although, as I'm writing this... perhaps what we want to do is only  
include the search method if an index is defined for that model (or a  
superclass)? That means it'll be there when needed, but otherwise it's  
kept out of sight.

I'll try to code that up, but patches are welcome if you want to try  
to beat me to it :)

Cheers

-- 
Pat

On 16/02/2009, at 4:38 AM, Christian Rishøj wrote:

>
>
> I have been using ThinkingSphinx in an application for a while, and
> now I wanted to keep a log of user searches, search strings and
> results and correlate this to what the user ends up purchasing on the
> site.
>
> Using the database for logging, I settled on the following models:
>
> class Search < ActiveRecord::Base
> has_many :search_criteria
> end
>
> class SearchCriterion < ActiveRecord::Base
> belongs_to :search
> end
>
> Now, when going through the belongs_to association,
> ThinkingSphinx::ActiveRecord::Search takes precedence over my model
> class Search:
>
>>> sc = SearchCriterion.first
> => #<SearchCriterion search_id: 145, field: :title, id: 1,
> search_string_id: 309>
>
>>> sc.search
> NoMethodError: undefined method `find' for
> ThinkingSphinx::ActiveRecord::Search:Module
>       from vendor/rails/activerecord/lib/active_record/associations/
> belongs_to_association.rb:44:in `find_target'
>       from vendor/rails/activerecord/lib/active_record/associations/
> association_proxy.rb:233:in `load_target'
>       from vendor/rails/activerecord/lib/active_record/associations/
> association_proxy.rb:112:in `reload'
>       from vendor/rails/activerecord/lib/active_record/associations.rb:
> 1249:in `search'
>       from (irb):10
>
> Any views on how to correct this?
> - Rename ThinkingSphinx::ActiveRecord::Search to e.g.
> ThinkingSphinx::ActiveRecord::SphinxSearch?
> - Put my models in a namespace?
> - Rename my model?
> - Revise Rails' behavior in ActiveRecord::Base#compute_type?
>
> Best regards
>
> Christian
>
> >


--~--~---------~--~----~------------~-------~--~----~
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