Skip to content
This repository

ScopeOptions delegates to a protected method of ActiveRecord::Base #7

Closed
bkerley opened this Issue · 3 comments

3 participants

Bryce "BonzoESC" Kerley Grant Hutchins Mateusz Sójka
Bryce "BonzoESC" Kerley

ScopeOptions delegates sanitize_sql_array to ActiveRecord::Base. In Rails 3.1, this is a protected method, and causes deprecation warnings:

DEPRECATION WARNING: Using Module#delegate to delegate to non-public methods is deprecated. Please declare your methods as public if they are going to accessed from other classes. (called from /Users/bkerley/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/pg_search-0.2/lib/pg_search/scope_options.rb:7)

These warnings add considerable noise to tests in my Rails application, and I'd like to figure out the best way to fix this.

  1. Re-implement sanitize_sql_array in the ScopeOptions class
  2. Work with the Rails team to make sanitize_sql_array public
  3. Cheat using send

Are there any better solutions than these?

Grant Hutchins
Collaborator

Long term I'd like to figure out how to use ARel to generate all of our SQL, so any solution that takes advantage of ARel would be preferred. But that's a pretty big refactor.

I'm leaning towards using send for the time being.

Mateusz Sójka

Well... Rails 4 does not allow delegating to protected methods at all, so it is basically broken.

I have monkey patched it this way:

module PgSearch
  class ScopeOptions

    def sanitize_sql_array(array)
      @model.send(:sanitize_sql_array, array)
    end
  end

end

I think this should be merged because soon people will start migrating to Rails 4. If you want, I can send a pull request with this change.

Grant Hutchins
Collaborator

I just merged #87 which works around it in a different way. I'm still going to work towards removing all calls to sanitize_sql_array by preferring Arel to SQL strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.