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

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Fixed
    • Priority: Unknown
    • 5.9.0
    • Affects Version/s: None
    • None
    • 5
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?

      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • 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:
              Jérôme Tamarelle
              Reporter:
              Jérôme Tamarelle
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: