-
Type:
New Feature
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
Component/s: Laravel
-
None
-
None
-
PHP Drivers
-
None
-
None
-
None
-
None
-
None
-
None
Context
The automatic top-level _id ↔ id aliasing introduced in v5.0 causes data corruption for users who have a business id field in their MongoDB documents alongside _id.
This has been requested by multiple users (see GitHub issues #3392, community forum threads).
Implementation
The id → _id column mutation is currently hardcoded in Builder::compileWheres(). It must be moved into a dedicated overridable method on the Grammar class, following the pattern established by prepareFieldsForQuery() (#3476).
This makes the aliasing behaviour substitutable: users who need to disable it can extend the Grammar class, consistent with Laravel's query builder architecture.
The alias_id connection config option (as proposed in #3472) is not the right approach because compileWheres() runs before Grammar::prepareFieldsForQuery(), so the Grammar hook receives a payload where id has already been replaced by _id.