Move id/_id column aliasing from Builder::compileWheres() to an overridable Grammar method

XMLWordPrintableJSON

    • 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 _idid 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.

            Assignee:
            Unassigned
            Reporter:
            Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: