Use model primary key for database queries instead of scout key name#982
Draft
JoshSalway wants to merge 4 commits intolaravel:11.xfrom
Draft
Use model primary key for database queries instead of scout key name#982JoshSalway wants to merge 4 commits intolaravel:11.xfrom
JoshSalway wants to merge 4 commits intolaravel:11.xfrom
Conversation
This section was already covered by the skill's description frontmatter and doesn't affect triggering behavior. See laravel/boost#669.
When getScoutKeyName() is overridden to return a different field name for the search index (e.g., 'id' for Meilisearch) that differs from the actual database primary key column (e.g., 'uuid'), database operations like chunkById, orderBy, whereIn, min, max, and whereBetween fail with "column not found" errors. This fix separates the two concerns: getScoutKeyName() continues to be used for search engine operations (indexing, document identification), while getKeyName() is now used for all database query operations (chunking, ordering, filtering by IDs). Affected files: - SearchableScope: chunkById now uses getKeyName() - Searchable: makeAllSearchableQuery and queryScoutModelsByIds - QueueImportCommand: min/max queries - MakeRangeSearchable: whereBetween query - DatabaseEngine: orderBy and primary key search - CollectionEngine: orderBy and result ID plucking Fixes laravel#960 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Thanks for submitting a PR! Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface. Pull requests that are abandoned in draft may be closed due to inactivity. |
Tests were still mocking getScoutKeyName() for database query operations (queryScoutModelsByIds, SearchableScope chunking) but the source code now correctly uses getKeyName() for these operations. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.
Summary
Fixes database query failures when
getScoutKeyName()is overridden to return a different field name than the model's actual primary key. Database operations (chunking, ordering, whereIn) were incorrectly using the Scout key name instead of the database primary key.Fixes #960
Problem
When a model overrides
getScoutKeyName()to return a search-engine-specific field name that differs from the database primary key, all database operations break:Solution
Separate the two concerns across all affected files (SearchableScope, Searchable trait, QueueImportCommand, MakeRangeSearchable, DatabaseEngine, CollectionEngine):
getScoutKeyName()getKeyName()Before/After
Before:
scout:importwith a customgetScoutKeyName()fails with "Column not found" because database queries use the Scout key name.After: Database queries use the model's actual primary key. Search engine operations continue using the Scout key name. Both work independently.
Test Plan
scout:importworks with default configuration (getScoutKeyName == getKeyName)scout:importworks when getScoutKeyName differs from getKeyName