Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Avoid overwriting existing search methods #1265

Merged
merged 1 commit into from
Jul 7, 2024
Merged

Conversation

pat
Copy link
Owner

@pat pat commented Jul 7, 2024

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

  • sphinx_search
  • sphinx_search_for_ids
  • sphinx_search_count
  • sphinx_facets

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

  • search
  • search_for_ids
  • search_count
  • facets

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.

@pat pat merged commit c0e8399 into develop Jul 7, 2024
266 checks passed
@ur5us
Copy link

ur5us commented Aug 9, 2024

@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}\" " \

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants