E535 Avoid overwriting existing search methods by pat · Pull Request #1265 · pat/thinking-sphinx · GitHub
[go: up one dir, main page]

Skip to content

Avoid overwriting existing search methods#1265

Merged
pat merged 1 commit intodevelopfrom
avoid_method_clobbering
Jul 7, 2024
Merged

Avoid overwriting existing search methods#1265
pat merged 1 commit intodevelopfrom
avoid_method_clobbering

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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0