pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 469 forks source link

Avoid overwriting existing search methods #1265

Closed pat closed 1 month ago

pat commented 1 month ago

This approach will always add the following methods to ActiveRecord::Base:

And then, if there aren't methods already existing without the sphinx_ prefix, they're also added:

This does not remove the possibility that something invoked after Thinking Sphinx will overwrite the search method, etc - but at least the sphinx_-prefixed versions will always be available.

This addresses #1264 and is an evolution of #1241.

ur5us commented 2 weeks ago

@pat Sadly, this doesn’t quite work as expected. The problem is that it only considers ActiveRecord::Base but none of models inheriting from it. Thus, it still explodes with the following error

ArgumentError: You tried to define a scope named "search" on the model "Content", but Active Record already defined a class method with the same name. (ArgumentError)

            raise ArgumentError, "You tried to define a scope named \"#{name}\" " \