Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/administrate/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ def query_table_name(attr)
else
@scoped_resource.reflect_on_association(attr).klass.table_name
end
ActiveRecord::Base.connection.quote_table_name(unquoted_table_name)
connection.quote_table_name(unquoted_table_name)
else
ActiveRecord::Base.connection
connection
.quote_table_name(@scoped_resource.table_name)
end
end

def column_to_query(attr)
ActiveRecord::Base.connection.quote_column_name(attr)
connection.quote_column_name(attr)
end

def tables_to_join
Expand All @@ -162,6 +162,14 @@ def term
query.terms
end

def connection
if @scoped_resource.respond_to?(:connection)
@scoped_resource.connection
else
ActiveRecord::Base
end
Comment on lines +166 to +170

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the test suite with the following change still fully passes:

      if @scoped_resource.respond_to?(:connection)
        @scoped_resource.connection
      else
-       ActiveRecord::Base
+       fail
      end

@nickcharlton @pablobm to me, that signals that the @scoped_resource will always be an ActiveRecord::Relation or ActiveRecord::Base-descended class. Conceptually, is that true?

If so, I'm happy to remove the else branch of this conditional and inline the #connection calls back into the original call sites.

end

attr_reader :resolver, :query
end
end