Skip to content

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

bkerley opened this Issue Sep 2, 2011 · 3 comments

3 participants

bkerley commented Sep 2, 2011

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?

nertzy commented Sep 3, 2011

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.

@nertzy nertzy was assigned Sep 11, 2011
yagooar commented Feb 24, 2013

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)


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.

nertzy commented Feb 24, 2013

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.

@nertzy nertzy closed this Feb 24, 2013
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.