Delegate Search connection to @scoped_resource#3049
Open
seanpdoyle wants to merge 1 commit into
Open
Conversation
seanpdoyle
force-pushed
the
query-multi-database-support
branch
from
July 20, 2026 14:07
e7d1713 to
ecff9e3
Compare
When an `Administrate::Search::Query` instance is constructed for a resource class that connects to a different database than the primary, connections scoped by `ActiveRecord::Base` fail to connect to the database specified by the class that descends from `ActiveRecord::Base` and declares its own `connect_to`. This commit modifies the `Administrate::Search::Query` class to access the connection through the `@scoped_resources` Active Record Relation instance when possible, falling back to `ActiveRecord::Base` when not possible.
seanpdoyle
force-pushed
the
query-multi-database-support
branch
from
July 20, 2026 14:35
ecff9e3 to
872e9f6
Compare
seanpdoyle
commented
Jul 20, 2026
Comment on lines
+166
to
+170
| if @scoped_resource.respond_to?(:connection) | ||
| @scoped_resource.connection | ||
| else | ||
| ActiveRecord::Base | ||
| end |
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an
Administrate::Search::Queryinstance is constructed for a resource class that connects to a different database than the primary, connections scoped byActiveRecord::Basefail to connect to the database specified by the class that descends fromActiveRecord::Baseand declares its ownconnect_to.This commit modifies the
Administrate::Search::Queryclass to access the connection through the@scoped_resourcesActive Record Relation instance when possible, falling back toActiveRecord::Basewhen not possible.